<template>
  <div id="create-plan">
    <div class="plan-card">
      <div class="plan-card-header">
        <div class="title">主宝贝商品信息</div>
      </div>
      <div class="plan-card-content other-style">
        <div>
          <el-form
            ref="goodsMainForm"
            :model="salesPlanForm"
            :rules="goodsMainRules"
            label-width="120px"
            class="goods-form"
          >
            <el-form-item label="计划名称 :" prop="planName">
              <el-input
                placeholder="请输入计划名称"
                size="small"
                v-model="salesPlanForm.planName"
                class="form-input"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item label="店铺名称 :" prop="shopId">
              <el-select
                :disabled="isForbidModify"
                v-model="salesPlanForm.shopId"
                class="form-input"
                placeholder="请选择店铺名称"
                size="small"
                filterable
                :filter-method="dataFilter"
              >
                <el-option
                  v-for="(stores, index) in shopNameList"
                  :key="index"
                  :label="stores.name"
                  :value="stores.id"
                ></el-option>
              </el-select>
              <!-- <el-input v-else  :disabled="isForbidModify" size="small" v-model="salesPlanForm.shopName" class="form-input"></el-input> -->
            </el-form-item>
            <el-form-item label="商品链接 :" prop="goodsUrl">
              <el-input
                placeholder="请输入商品链接"
                v-model="salesPlanForm.goodsUrl"
                size="small"
                :disabled="isForbidModify"
                class="form-input"
                @blur="changeGoodsUrl"
              ></el-input>
              <div style="display: inline-block;" v-if="!isForbidModify">
                <el-button
                  class="form-btn"
                  @click="goodsInfo"
                  v-if="!isWphMainUrl"
                >抓取商品信息
                </el-button
                >
                <div class="form-btn-tips" v-else>唯品会需要手动输入</div>
                <el-button class="form-btn" @click="showSelectGoodsDialog"
                >选择商品
                </el-button
                >
              </div>
            </el-form-item>
            <el-form-item label="商品id :" prop="productId">
              <el-input
                placeholder
                v-model="salesPlanForm.productId"
                size="small"
                :disabled="true"
                class="form-input"
              ></el-input>
            </el-form-item>
            <el-form-item label="店铺种类 :" prop="shopType">
              <el-select
                v-model="salesPlanForm.shopType"
                :disabled="isForbidRevise"
                placeholder="请选择店铺种类"
                size="small"
                @change="platFormTypeChange"
                class="form-input"
              >
                <el-option
                  v-for="(stores, index) in platformTypeList"
                  :key="index"
                  :label="stores.label"
                  :value="stores.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品标题 :" prop="goodsTitle">
              <el-input v-if='salesPlanForm.shopType==4'
                        placeholder="请输入商品标题"
                        v-model="salesPlanForm.goodsTitle"
                        size="small"
                        class="form-input"
              ></el-input>
              <el-input v-else
                        placeholder="请输入商品标题"
                        v-model="salesPlanForm.goodsTitle"
                        size="small"
                        :disabled="isForbidRevise"
                        class="form-input"
              ></el-input>
            </el-form-item>
            <el-form-item label="店铺名称 :" prop="shopName">
              <el-input v-if='salesPlanForm.shopType==4'
                        placeholder
                        v-model="salesPlanForm.shopName"
                        class="form-input"
                        size="small"
                        clearable
              ></el-input>
              <el-input v-else
                        placeholder
                        :disabled="isForbidRevise"
                        v-model="salesPlanForm.shopName"
                        class="form-input"
                        size="small"
                        clearable
              ></el-input>
            </el-form-item>
            <el-form-item
              label="掌柜昵称 :"
              prop="goodsSeller"
              v-if="salesPlanForm.shopType == 1 || salesPlanForm.shopType == 2"
            >
              <el-input
                placeholder
                :disabled="isForbidRevise"
                v-model="salesPlanForm.goodsSeller"
                class="form-input"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
            <!-- 入口类型 -->
            <el-form-item label="入口类型 :" prop="entranceType">
              <el-select
                v-model="salesPlanForm.entranceType"
                :disabled="!isForbidRevise"
                placeholder="请选择入口类型"
                size="small" @change="
                  val => {
                    entranceTypeChange(val, salesPlanForm);
                  }
                "
                class="form-input"
              >
                <el-option
                  v-for="(stores, index) in entranceTypeList"
                  :key="index"
                  :label="stores.label"
                  :value="stores.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              v-if="salesPlanForm.entranceType == 3"
              label="二维码："
              prop="keyword"
            >
              <img
                :src="salesPlanForm.keyword"
                alt=""
                v-if="salesPlanForm.keyword && isForbidModify"
              />

              <div class="qrcode-img-box" v-else>
                <!-- 点击上传图片 -->
                <el-upload
                  class="upload-box"
                  :action="BASE_API_URL + 'baseapi/wechart/uploadMerchantPushImg'"
                  :data="uploadQrcodeData"
                  :show-file-list="false"
                  :on-success="qrcodeSuccess"
                  :before-upload="qrcodeBeforeAvatarUpload"
                >
                  <img
                    v-if="salesPlanForm.keyword"
                    :src="salesPlanForm.keyword"
                    class="avatar"
                  />
                  <i v-else class="upload-icon el-icon-ali-upload"></i>
                </el-upload>
              </div>
            </el-form-item>
            <!-- 关键词 等等 -->
            <el-form-item
              v-else
              :label="entranceTypeName[salesPlanForm.entranceType] + ':'"
              prop="keyword"
            >
              <el-input
                class="planInfo-input"
                type="textarea"
                size="small"
                @blur="expressionFilter(salesPlanForm)"
                @input="inputUpdate($event)"
                autosize
                :disabled="isForbidModify"
                placeholder="请输入内容"
                v-model="salesPlanForm.keyword"
              ></el-input>
            </el-form-item>
            <div class="other-info">
              <el-form-item
                label="销量任务 :"
                class="set-error-msg"
                prop="taskNum"
              >
                <el-input
                  type="number"
                  v-model.number="salesPlanForm.taskNum"
                  onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
                单
              </el-form-item>
              <el-form-item
                label="每单拍 :"
                class="set-error-msg"
                prop="buyNum"
              >
                <el-input
                  type="number"
                  v-model.number="salesPlanForm.buyNum"
                  onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
                件
              </el-form-item>
            </div>
            <div class="order-info">
              <el-form-item
                label="拍下单价 :"
                class="set-error-msg"
                prop="payMoney"
              >
                <el-input
                  type="number"
                  v-model.number="salesPlanForm.payMoney"
                  onKeypress="return(/[\d|\.]/.test(String.fromCharCode(event.keyCode)))"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="拍下规格 :"
                class="set-error-msg"
                prop="sku"
              >
                <el-input
                  type="text"
                  v-model="salesPlanForm.sku"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
              </el-form-item>
            </div>
            <div class="order-info">
              <el-form-item
                label="搜索展示价格 :"
                class="set-error-msg"
                prop="showMoney"
              >
                <el-input
                  type="number"
                  v-model.number="salesPlanForm.showMoney"
                  onKeypress="return(/[\d|\.]/.test(String.fromCharCode(event.keyCode)))"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
              </el-form-item>
              <el-form-item label="付款人数约 :" prop="payPerson">
                <el-input
                  type="number"
                  v-model.number="salesPlanForm.payPerson"
                  onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="商品归属地 :"
                prop="goodsAddress"
                v-if="salesPlanForm.shopType == 1 || salesPlanForm.shopType == 2"
              >
                <el-input
                  v-model="salesPlanForm.goodsAddress"
                  auto-complete="off"
                  size="small"
                  class="other-info-input"
                  :disabled="isForbidModify"
                ></el-input>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="goods-img-box">
          <div class="goods-img" v-if="salesPlanForm.goodsMainImg && isForbidModify">
            <img :src="salesPlanForm.goodsMainImg" alt=""/>
            <p>商品主图</p>
          </div>
          <div class="goods-img" v-else>
            <el-upload
              class="avatar-uploader"
              :action="BASE_API_URL + 'baseapi/wechart/uploadMerchantPushImg'"
              :data="uploadData"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img
                v-if="salesPlanForm.goodsMainImg"
                :src="salesPlanForm.goodsMainImg"
                class="avatar"
              />
              <i v-else class="upload-icon el-icon-ali-upload"></i>
            </el-upload>
            <p>商品主图</p>
          </div>
        </div>
      </div>
    </div>
    <div class="plan-card">
      <div class="plan-card-header">
        <div class="title">副宝贝商品信息<br/><b style="color: red; font-size: 13px">*每添加一个链接 +{{payPlanInfo.copyCommission}} 元</b></div>
      </div>
      <div class="plan-card-content">
        <div
          v-if="salesPlanForm.goodsItems.length == 0"
          class="task-card"
        >
          <div class="task-card-right">
            <i
              class="add-task-icon el-icon-ali-add"
              @click="addTask"
            ></i>
          </div>
        </div>
        <div
          v-if="salesPlanForm.goodsItems.length != 0"
          class="task-card"
          v-for="(goodsItem, index) in salesPlanForm.goodsItems"
          :key="index"
        >
          <div>
            <el-form
              ref="goodsForm"
              :model="goodsItem"
              :rules="goodsRules"
              label-width="120px"
              class="goods-form"
            >
              <el-form-item label="商品链接 :" prop="goodsUrlSon">
                <el-input
                  placeholder="请输入商品链接"
                  v-model="goodsItem.goodsUrlSon"
                  size="small"
                  :disabled="isForbidModify"
                  class="form-input"
                  @blur="changeGoodsUrlSon(index)"
                  @input="updateData"
                ></el-input>
                <div style="display: inline-block;" v-if="!isForbidModify">
                  <!--<el-button
                    class="form-btn"
                    @click="goodsInfo(2)"
                    v-if="!isWphUrl"
                  >抓取商品信息</el-button
                  >
                  <div class="form-btn-tips" v-else>唯品会需要手动输入</div>
                  <el-button class="form-btn" @click="showSelectGoodsDialog(2)"
                  >选择商品</el-button
                  >-->
                  <el-button
                    class="form-btn"
                    @click="goodsInfoSon(index)"
                    v-if="!isWphUrl"
                  >抓取商品信息
                  </el-button
                  >
                  <div class="form-btn-tips" v-else>唯品会需要手动输入</div>
                  <el-button class="form-btn" @click="showSelectGoodsDialogSon(index)"
                  >选择商品
                  </el-button
                  >
                </div>
              </el-form-item>
              <el-form-item label="商品id :" prop="productIdSon">
                <el-input
                  placeholder
                  v-model="goodsItem.productIdSon"
                  size="small"
                  :disabled="true"
                  class="form-input"
                ></el-input>
              </el-form-item>
              <el-form-item label="商品标题 :" prop="goodsTitleSon">
                <el-input v-if='salesPlanForm.shopType==4'
                          placeholder="请输入商品标题"
                          v-model="goodsItem.goodsTitleSon"
                          size="small"
                          class="form-input"
                ></el-input>
                <el-input v-else
                          placeholder="请输入商品标题"
                          v-model="goodsItem.goodsTitleSon"
                          size="small"
                          :disabled="isForbidRevise"
                          class="form-input"
                ></el-input>
              </el-form-item>
              <!-- 销量展示 -->
              <div v-if="creatPlanType == 'sales'">
                <div class="other-info">
                  <el-form-item
                    label="每单拍 :"
                    class="set-error-msg"
                    prop="buyNumSon"
                  >
                    <el-input
                      type="number"
                      v-model.number="goodsItem.buyNumSon"
                      onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
                      auto-complete="off"
                      size="small"
                      class="other-info-input"
                      :disabled="isForbidModify"
                      @input="updateData"
                    ></el-input>
                    件
                  </el-form-item>
                </div>
                <div class="order-info">
                  <el-form-item
                    label="拍下单价 :"
                    class="set-error-msg"
                    prop="payMoneySon"
                  >
                    <el-input
                      type="number"
                      v-model.number="goodsItem.payMoneySon"
                      @input="updateData"
                      onKeypress="return(/[\d|\.]/.test(String.fromCharCode(event.keyCode)))"
                      auto-complete="off"
                      size="small"
                      class="other-info-input"
                      :disabled="isForbidModify"
                    ></el-input>
                  </el-form-item>
                  <el-form-item
                    label="拍下规格 :"
                    class="set-error-msg"
                    prop="skuSon"
                  >
                    <el-input
                      type="text"
                      v-model="goodsItem.skuSon"
                      auto-complete="off"
                      size="small"
                      class="other-info-input"
                      :disabled="isForbidModify"
                      @input="updateData"
                    ></el-input>
                  </el-form-item>
                  <!-- 搜索展示价格 -->
                  <el-form-item
                    label="搜索展示价格 :"
                    class="set-error-msg"
                    prop="showMoneySon"
                  >
                    <el-input
                      type="number"
                      v-model.number="goodsItem.showMoneySon"
                      onKeypress="return(/[\d|\.]/.test(String.fromCharCode(event.keyCode)))"
                      auto-complete="off"
                      size="small"
                      class="other-info-input"
                      :disabled="isForbidModify"
                      @input="updateData"
                    ></el-input>
                  </el-form-item>
                  <el-form-item
                    label="商品归属地 :"
                    prop="goodsAddressSon"
                    v-if="salesPlanForm.shopType == 1 || salesPlanForm.shopType == 2"
                  >
                    <el-input
                      v-model="goodsItem.goodsAddressSon"
                      auto-complete="off"
                      size="small"
                      class="other-info-input"
                      :disabled="isForbidModify"
                      @input="updateData"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
              <!-- 流量展示 -->
              <div class="task-card-center flow-center" v-else>
                <div
                  class="center-row"
                  v-for="(item, itemIndex) in taskTypeList"
                  :key="itemIndex"
                >
                  <div
                    class="flow-form-box"
                    v-for="(cell, cellIndex) in item.list"
                    :key="cellIndex"
                  >
                    <span class="title">{{ cell.name }}：</span>
                    <el-input
                      type="number"
                      size="small"
                      @input="inputUpdate($event)"
                      onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
                      :disabled="isForbidModify"
                      v-model="task.taskType[cell.type]"
                      class="form-input"
                    ></el-input>
                  </div>
                </div>
              </div>
            </el-form>
          </div>
          <div class="goods-img-box">
            <div class="goods-img" v-if="goodsItem.goodsImg && isForbidModify">
              <img :src="goodsItem.goodsImg" alt=""/>
              <p>商品主图</p>
            </div>
            <div class="goods-img" v-else>
              <el-upload
                class="avatar-uploader"
                :action="BASE_API_URL + 'baseapi/wechart/uploadMerchantPushImg'"
                :data="uploadData"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img
                  v-if="goodsItem.goodsImg"
                  :src="goodsItem.goodsImg"
                  class="avatar"
                />
                <i v-else class="upload-icon el-icon-ali-upload"></i>
              </el-upload>
              <p>商品主图</p>
            </div>
          </div>
          <div class="task-card-right" v-if="!isForbidModify">
            <i
              class="cut-task-icon el-icon-ali-cut"
              @click="cutTask(index)"
            ></i>
            <i
              class="add-task-icon el-icon-ali-add"
              v-if="index == salesPlanForm.goodsItems.length - 1"
              @click="addTask"
            ></i>
            <!--<i
              class="cut-task-icon el-icon-ali-cut"
              @click="cutTask(index)"
              v-if="salesPlanForm.goodsItems.length != 1"
            ></i>
            <i
              class="add-task-icon el-icon-ali-add"
              @click="addTask"
              v-if="index == salesPlanForm.goodsItems.length - 1"
            ></i>-->
          </div>
        </div>
      </div>
    </div>
    <div class="plan-card">
      <div class="plan-card-header">
        <div class="title">发布时间设置</div>
        <div class="tips">*开始时间不能大于结束时间！</div>
      </div>
      <div class="plan-card-content">
        <div class="time-type-box">
          <div class="title">设置类型：</div>
          <div class="tabs-nav" :class="isForbidModify ? 'disabled-click' : ''">
            <div
              class="tab"
              :class="salesPlanForm.allotType == item.type ? 'active' : ''"
              v-for="(item, index) in tabsList"
              :key="index"
              @click="changeTimeTab(item.type)"
            >
              {{ item.name }}
            </div>
          </div>
        </div>
        <div class="set-time-box">
          <div class="title">设置时间：</div>
          <div class="time-select-box" v-if="salesPlanForm.allotType == 1">
            <el-date-picker
              v-model="setPlanTime.startTime"
              :disabled="isForbidModify"
              :picker-options="pickerOptions1"
              type="datetime"
              placeholder="选择日期时间"
              value-format="timestamp"
              @change="changeDate"
            ></el-date-picker>
            ~
            <el-date-picker
              type="datetime"
              :disabled="isForbidModify"
              placeholder="选择日期时间"
              :picker-options="pickerOptions1"
              value-format="timestamp"
              v-model="setPlanTime.endTime"
              @change="changeDate"
            ></el-date-picker>
            <el-checkbox
              class="check-box"
              :disabled="isForbidModify"
              v-model="salesPlanForm.planOver"
              :true-label="1"
              :false-label="2"
            >设置计划终止时间:
            </el-checkbox
            >
            <el-date-picker
              type="datetime"
              :picker-options="pickerOptions1"
              placeholder="选择日期时间"
              value-format="timestamp"
              v-model="salesPlanForm.planOver == 2 ? '' : setPlanTime.overTime"
              :disabled="salesPlanForm.planOver == 2 ? true : false"
              @change="changeOverTime"
            ></el-date-picker>
          </div>
          <div class="time-select-box" v-else-if="salesPlanForm.allotType == 2">
            <el-date-picker
              v-model="setPlanTime.startTime"
              :disabled="isForbidModify"
              type="datetime"
              placeholder="选择日期时间"
              value-format="timestamp"
              @change="changeManualAllocationTime"
              @blur="selectDate"
            ></el-date-picker>
            ~
            <!--             <el-date-picker type="datetime" placeholder="选择日期时间" :picker-options="pickerOptions1" value-format="timestamp" v-model="setPlanTime.endTime" @change="changeManualAllocationEndTime" @blur="selectDate"></el-date-picker>-->
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              value-format="timestamp"
              v-model="setPlanTime.endTime"
              @change="changeManualAllocationEndTime"
              @blur="selectDate"
            ></el-date-picker>
            <el-checkbox
              class="check-box"
              :disabled="isForbidModify"
              v-model="salesPlanForm.planOver"
              :true-label="1"
              :false-label="2"
            >设置计划终止时间:
            </el-checkbox
            >
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              value-format="timestamp"
              v-model="salesPlanForm.planOver == 2 ? '' : setPlanTime.overTime"
              :disabled="salesPlanForm.planOver == 2 ? true : false"
              @change="changeOverTime"
            ></el-date-picker>
          </div>
          <div class="time-select-box" v-else>
            <el-date-picker
              v-model="setPlanTime.startTime"
              :disabled="isForbidModify"
              :picker-options="pickerOptions2"
              type="datetime"
              placeholder="选择日期时间"
              value-format="timestamp"
              @change="changeStartTime"
            ></el-date-picker>
            <el-checkbox
              class="check-box"
              :disabled="isForbidModify"
              v-model="salesPlanForm.planOver"
              :true-label="1"
              :false-label="2"
            >设置计划终止时间:
            </el-checkbox
            >
            <el-date-picker
              type="datetime"
              :picker-options="pickerOptions2"
              placeholder="选择日期时间"
              value-format="timestamp"
              v-model="salesPlanForm.planOver == 2 ? '' : setPlanTime.overTime"
              :disabled="salesPlanForm.planOver == 2 ? true : false"
              @change="changeOverTime"
            ></el-date-picker>
          </div>
        </div>
        <div class="set-number" v-if="salesPlanForm.allotType == 2">
          <div class="title">数量设置：</div>
          <el-collapse>
            <div
              class="set-n-row"
              v-for="(item, key, index) in salesPlanForm.planTime"
              :key="index"
            >
              <el-collapse-item>
                <template slot="title">
                  <div>
                    <el-tag>{{ getMonthAndDay(parseInt(key)) }}</el-tag>
                  </div>
                </template>
                <div>
                  <div
                    class="plan-time-box"
                    v-for="(subItem, subKey, subIndex) in item"
                    :key="subIndex"
                  >
                    <div class="time">
                      {{ getDateOfHours(parseInt(subKey)) }}:00
                    </div>
                    <el-input-number
                      :disabled="isForbidEditNum"
                      :min="0"
                      v-model="item[subKey]"
                      controls-position="right"
                      @change="changeAllotNum(item, subKey)"
                    ></el-input-number>
                  </div>
                </div>
              </el-collapse-item>
            </div>
          </el-collapse>
          <div class="count-number">
            <span
            >计划中单数:<span>{{ countIntendOrderNum() }}</span
            >&nbsp;,&nbsp;</span
            >
            <span
            >已分配总计:<span>{{ totalAllotNum }}</span></span
            >
          </div>
        </div>
        <div class="remark-box">
          <div class="remark-example-box" v-if="!isForbidModify">
            <div
              class="remark-example"
              @click="clickRemarkText(rm.remark)"
              v-for="(rm, rmIndex) in remarkList"
              :key="rmIndex"
            >
              {{ rm.remark }}
            </div>
          </div>
          <div class="textarea-box">
            <span class="title">*</span>商家要求(150字以内)：
            <el-input
              type="textarea"
              :disabled="isForbidModify"
              placeholder="请输入内容"
              style="width: 500px;"
              v-model="salesPlanForm.remark"
              maxlength="150"
            ></el-input>
          </div>
        </div>
      </div>
    </div>
    <div class="plan-card">
      <div class="plan-card-header">
        <div class="title">接单设置</div>
        <div class="tips">*可按需要设置，不设置计划将会随机分配！</div>
      </div>
      <div class="plan-card-content">
        <el-form>
          <el-form-item
            label="选择区域 :"
            v-if="tagsList.address_list && tagsList.address_list.status == 1"
          >
            <el-button
              size="small"
              :disabled="isForbidModify"
              class="select-area-btn"
              @click="showAreaDialog"
            >{{
              salesPlanForm.placementArea ? salesPlanForm.placementArea : "不限"
              }}
            </el-button
            >
          </el-form-item>
          <el-form-item
            label="选择性别 :"
            v-if="
              showSexArr.indexOf(salesPlanForm.shopType) >= 0 &&
                tagsList.sex_list &&
                tagsList.sex_list.status == 1
            "
          >
            <el-select
              size="small"
              placeholder="请选择性别"
              :disabled="isForbidModify"
              clearable
              v-model="salesPlanForm.sexId"
              v-if="tagsList.sex_list && tagsList.sex_list.sex_list"
            >
              <el-option label="不限" value="99"></el-option>
              <el-option
                v-for="(item, index) in tagsList.sex_list.sex_list"
                :key="index"
                v-if="item.status == 1"
                :label="item.tag_name"
                :value="item.id"
              ></el-option>
            </el-select>
            <div v-if="salesPlanForm.shopType" class="price-text">
              (每单{{ getTagsDefaultPrice("买手性别") }})
            </div>
          </el-form-item>
          <el-form-item
            label="选择年龄 :"
            v-if="tagsList.age_list && tagsList.age_list.status == 1"
          >
            <el-select
              multiple
              size="small"
              placeholder="请选择年龄"
              :disabled="isForbidModify"
              clearable
              v-model="ageIdArr"
              @change="changeAge"
              v-if="tagsList.age_list && tagsList.age_list.age_list"
            >
              <el-option label="不限" value="99"></el-option>
              <el-option
                v-for="(item, index) in tagsList.age_list.age_list"
                :key="index"
                v-if="item.status == 1"
                :label="item.tag_name"
                :value="item.id"
              ></el-option>
            </el-select>
            <div v-if="salesPlanForm.shopType" class="price-text">
              (每单{{ getTagsDefaultPrice("买手年龄") }})
            </div>
          </el-form-item>
          <el-form-item
            label="推手信用 :"
            v-if="
              showCreditArr.indexOf(salesPlanForm.shopType) >= 0 &&
                tagsList.credit_list &&
                tagsList.credit_list.status == 1
            "
          >
            <el-select
              size="small"
              placeholder="请选择推手信用"
              :disabled="isForbidModify"
              clearable
              v-model="salesPlanForm.creditId"
              v-if="tagsList.credit_list && tagsList.credit_list.credit_list"
            >
              <el-option label="不限" value="99"></el-option>
              <el-option
                v-for="(item, index) in tagsList.credit_list.credit_list"
                :key="index"
                v-if="item.status == 1"
                :label="item.tag_name"
                :value="item.id"
              ></el-option>
            </el-select>
            <div v-if="salesPlanForm.shopType" class="price-text">
              (每单{{ getTagsDefaultPrice("信用") }})
            </div>
          </el-form-item>
          <el-form-item
            label="选择机型 :"
            v-if="tagsList.model_list && tagsList.model_list.status == 1"
          >
            <el-select
              size="small"
              placeholder="请选择机型"
              :disabled="isForbidModify"
              clearable
              v-model="salesPlanForm.modelId"
              v-if="tagsList.model_list && tagsList.model_list.model_list"
            >
              <el-option label="不限" value="99"></el-option>
              <el-option
                v-for="(item, index) in tagsList.model_list.model_list"
                :key="index"
                v-if="item.status == 1"
                :label="item.tag_name"
                :value="item.id"
              ></el-option>
            </el-select>
            <div v-if="salesPlanForm.shopType" class="price-text">
              (每单{{ getTagsDefaultPrice("手机机型") }})
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div
      class="plan-card"
      v-if="
        showCheckContentArr.indexOf(salesPlanForm.shopType) >= 0 &&
          checkContentStatus
      "
    >
      <div class="plan-card-header">
        <div class="title">主宝贝问答设置</div>
        <div class="tips">
          *请从该商品的商品详情页提取连续5个字，作为推手验证的文本！！
        </div>
      </div>
      <div class="plan-card-content">
        <div class="tips">注：请用手淘端详情页文字</div>
        <div class="check-content-box">
          <span class="title">商品详情页连续5个字文本 :</span>
          <el-input
            class="input"
            :disabled="isForbidModify"
            placeholder="请输入商品详情页文本"
            @blur="getCheckContentText"
            maxlength="5"
            v-model="salesPlanForm.checkContent"
            size="small"
          ></el-input>
          <span
          >注： 推手需提交中间的文字去验证：<span class="tips">{{
              checkContent
            }}</span></span
          >
        </div>
      </div>
    </div>
    <!--<div
      class="plan-card"
      v-if="
        creatPlanType == 'sales' && showZqdArr.indexOf(salesPlanForm.shopType) >= 0
      "
    >
      <div class="plan-card-header">
        <div class="title">预约增权单设置</div>
        <div class="tips">
          *此选项选择是，则整个计划的任务只有今天之前做过该商品的流量任务的人才能接到。
        </div>
      </div>
      <div class="plan-card-content">
        <div class="zqd-tips" v-if="salesPlanForm.zqd == 1">
          如果选择【是】,确保您今天之前已经放过该商品的流量任务，否则任务将不能派单！
        </div>
        <div>
          <span class="title">预约增权单 :</span>
          <el-radio-group class="radio-box" v-model="salesPlanForm.zqd">
            <el-radio :disabled="isForbidModify" :label="1">是</el-radio>
            <el-radio :disabled="isForbidModify" :label="2">否</el-radio>
          </el-radio-group>
          <div v-if="salesPlanForm.shopType" class="price-text">
            (每单{{ getTagsDefaultPrice("预约增权") }})
          </div>
        </div>
        <div class="zpd-type-data" v-if="salesPlanForm.zqd == 1">
          <el-radio-group v-model="salesPlanForm.zqdType">
            <el-radio
              v-for="(cell, cellIndex) in zqdTypeData"
              :key="cellIndex"
              :disabled="isForbidModify"
              :label="cell.value"
            >{{ cell.label }}
            </el-radio
            >
          </el-radio-group>
        </div>
      </div>
    </div>-->
    <div class="plan-card" v-if="creatPlanType == 'sales' && tkCheckType == 1">
      <div class="plan-card-header">
        <div class="title">是否禁用淘客设置</div>
      </div>
      <div class="plan-card-content">
        <span class="title">是否禁用淘客 :</span>
        <el-radio-group class="radio-box" v-model="salesPlanForm.tk">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="2">否</el-radio>
        </el-radio-group>
        <div v-if="salesPlanForm.shopType" class="price-text">
          (每单{{ getTagsDefaultPrice("淘客检查") }})
        </div>
      </div>
    </div>
    <div class="page-footer">
      <el-button class="show-pay-info-btn" @click="creatPlan">{{
        planType == "pay" ? "支付计划" : "创建计划"
        }}
      </el-button>
    </div>
    <el-dialog
      title="选择商品"
      :visible.sync="isShowGoodsDialog"
      width="950px"
      class="dialog-style select-goods-modal"
    >
      <div class="select-goods-modal-header">
        <el-form>
          <el-form-item label="店铺类型：">
            <el-select
              v-model="goodsSelect.shopType"
              placeholder="请选择店铺"
              size="small"
            >
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="(item, index) in platformTypeList"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="店铺名称：">
            <el-select
              v-model="goodsSelect.shopId"
              placeholder="请选择店铺"
              size="small"
            >
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="(item, index) in shopNameList"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="商品ID：">
            <el-input
              size="small"
              placeholder="请输入商品ID"
              v-model="goodsSelect.productId"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item style="width: 100px;">
            <el-button
              class="inquire-btn"
              icon="el-icon-ali-search"
              @click="searchGoodsData"
            >查询
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="select-goods-modal-content">
        <div
          class="goods-img-box"
          v-for="(item, index) in goodsList"
          :key="index"
          :class="curSelectGoodsIndex == item.id ? 'selectStyle' : ''"
          @click="selectGoods(item, item.id)"
        >
          <img class="goods-img" :src="item.goods_img" alt=""/>
          <div class="text">店铺名称:{{ item.shop_name }}</div>
          <div class="text">商品ID:{{ item.product_id }}</div>
        </div>
        <div class="no-data-img" v-if="goodsList.length == 0">
          <img src="../../assets/image/no-data.png" alt=""/>
          <div class="tips">暂无数据</div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancel-btn" @click="isShowGoodsDialog = false"
        >取消
        </el-button
        >
        <el-button class="submit-btn" @click="sumbitSelectGoods(curSelectGoods)"
        >确认
        </el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      title="选择商品"
      :visible.sync="isShowGoodsDialogSon"
      width="950px"
      class="dialog-style select-goods-modal"
    >
      <div class="select-goods-modal-header">
        <el-form>
          <el-form-item label="店铺类型：">
            <el-select
              v-model="goodsSelect.shopType"
              placeholder="请选择店铺"
              size="small"
            >
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="(item, index) in platformTypeList"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="店铺名称：">
            <el-select
              v-model="goodsSelect.shopId"
              placeholder="请选择店铺"
              size="small"
            >
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="(item, index) in shopNameList"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="商品ID：">
            <el-input
              size="small"
              placeholder="请输入商品ID"
              v-model="goodsSelect.productId"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item style="width: 100px;">
            <el-button
              class="inquire-btn"
              icon="el-icon-ali-search"
              @click="searchGoodsData"
            >查询
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="select-goods-modal-content">
        <div
          class="goods-img-box"
          v-for="(item, index) in goodsList"
          :key="index"
          :class="curSelectGoodsIndex == item.id ? 'selectStyle' : ''"
          @click="selectGoods(item, item.id)"
        >
          <img class="goods-img" :src="item.goods_img" alt=""/>
          <div class="text">店铺名称:{{ item.shop_name }}</div>
          <div class="text">商品ID:{{ item.product_id }}</div>
        </div>
        <div class="no-data-img" v-if="goodsList.length == 0">
          <img src="../../assets/image/no-data.png" alt=""/>
          <div class="tips">暂无数据</div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancel-btn" @click="isShowGoodsDialogSon = false"
        >取消
        </el-button
        >
        <el-button class="submit-btn" @click="sumbitSelectGoodsSon(curSelectGoods)"
        >确认
        </el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      title="选择投放区域"
      :visible.sync="isShowAreaDialog"
      width="900px"
      class="area-dialog"
    >
      <template>
        <div class="tips">*默认全部地区投放（不投放地区可以去掉勾选）</div>
        <div class="area-content">
          <div
            class="province-select"
            v-for="(item, index) in provinceOpitons"
            :key="index"
          >
            <!--{
            area: "华东地区",
            province: ["北京市", "天津市", "河北省", "山西省", "内蒙古自治区"],
            checkedCities: [
            "北京市",
            "天津市",
            "河北省",
            "山西省",
            "内蒙古自治区"
            ],
            isIndeterminate: false,// 是否全选地区
            checkAll: true
            },-->
            <div class="left-box">
              <el-checkbox
                :indeterminate="item.isIndeterminate"
                v-model="item.checkAll"
                @change="handleCheckAllChange($event, item)"
              >{{ item.area }}
              </el-checkbox
              >
            </div>
            <div style="display: inline-block;">
              <el-checkbox-group
                v-model="item.checkedCities"
                @change="handleCheckedProvinceChange($event, item)"
              >
                <el-checkbox
                  v-for="city in item.province"
                  :label="city"
                  :key="city"
                >{{ city }}
                </el-checkbox
                >
              </el-checkbox-group>
            </div>
          </div>
        </div>
      </template>
      <span slot="footer" class="dialog-footer" style="position: relative; ">
        <div class="save-btn">
          <el-button @click="saveAreaData">保存设置</el-button>
        </div>
      </span>
    </el-dialog>
    <el-dialog
      title="支付计划"
      :visible.sync="isShowPayPlanDialog"
      width="700px"
      class="dialog-style pay-plan-dialog"
    >
      <div class="dialog-content">
        <div class="card">
          <div class="title">任务店铺</div>
          <div class="content">
            {{ salesPlanForm.shopName == "" ? "--" : salesPlanForm.shopName }}
          </div>
        </div>
        <div class="card">
          <div class="title">拍下数量</div>
          <div class="content">
            {{ salesPlanForm.taskNum == "" ? "--" : salesPlanForm.taskNum }}
          </div>
        </div>
        <div class="card">
          <div class="title">计划时间</div>
          <div class="content">{{ payPlanInfo.planTime }}</div>
        </div>
        <div class="card" v-if="creatPlanType == 'sales'">
          <div class="title">本金(拍下单价*件数*单数)</div>
          <div class="content">{{ payPlanInfo.capital }}</div>
          <span
            style="color: red;margin: 0 20px;"
            v-if="salesPlanForm.rebateType == 1"
          >商家返款本金</span
          >
        </div>
        <div class="card">
          <div class="title">佣金(单数*服务佣金)</div>
          <div class="content">{{ payPlanInfo.commission }}</div>
        </div>
        <div class="card">
          <div class="title">副宝贝(单数*副宝贝件数*服务佣金)</div>
          <div class="content">{{ payPlanInfo.commissionShow }}</div>
        </div>
        <div class="card" v-if="isShowOtherService">
          <div class="title">其他服务</div>
          <div class="content">
            <div
              v-for="(item, index) in payPlanInfo.otherService"
              :key="index"
              v-if="item.isShow"
            >
              {{ item.name }}：{{ item.price }}
            </div>
          </div>
        </div>
        <div class="card">
          <div class="title">本次合计冻结金额</div>
          <div class="content">{{ payPlanInfo.freezeMoney }}</div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancel-btn" @click="isShowPayPlanDialog = false"
        >返回修改
        </el-button
        >
        <el-button
          class="submit-btn"
          :disabled="submitLoading"
          :loading="submitLoading"
          @click="payPlan"
        >确认
        </el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    apiShopTagInfo,
    apiGetGoodsInfo,
    apiMerchantGoods,
    apiGetRemarkList,
    apiGetServiceFeeList,
    apiMerchantUserStatus,
    apiCreateSaleDragPlan,
    apiCreateFlowPlan,
    apiCopyPlan,
    apiFlowDetail,
    apiIsBindShop,
    apiOneDragInfo
  } from "../../request/api.js";
  import {mapGetters, mapActions} from "vuex";
  import moment from "moment";

  export default {
    data() {
      return {
        accessoryLimit: 0,// 副宝贝数量限制
        sonIndex: 0,// 副宝贝下标（区分选择商品的渲染问题）
        // activeName: 'tab1',
        creatPlanType: "sales", //计划类型
        isForbidModify: false, //重新支付禁止修改
        isForbidRevise: false, //抓取商品信息成功后禁止修改信息
        trafficOrderNum: 0,
        salesPlanForm: {
          token: "",
          shopId: "",
          shopName: "",
          productId: "",
          planName: "",
          payMoney: "",
          goodsUrl: "",
          goodsTitle: "",
          shopType: "",
          goodsSeller: "",
          showMoney: "",
          payPerson: "",
          goodsAddress: "",
          goodsMainImg: "",
          // goodsImg: "",
          taskNum: "1", // 销量任务
          buyNum: 1,
          sku: 1,
          entranceType: 1, // 入口类型
          goodsItems: [
            /*{
              /!*keyword: "",
              payMoney: "",
              sku: "",
              entranceType: 1,
              taskNum: 1,
              buyNum: 1*!/
              goodsUrlSon: "",
              productIdSon: "",
              goodsTitleSon: "",
              buyNumSon: "",
              payMoneySon: "",
              skuSon: "",
              goodsImg: ""
            }*/
          ],
          allotType: 1,
          planOver: 2,
          startTime: "",
          endTime: "",
          overTime: "",
          planTime: "",
          remark: "",
          placementArea: "",
          ageId: "99",
          sexId: "99",
          creditId: "99",
          modelId: "99",
          checkContent: "",
          rebateType: "",
          tk: 2,
          zqdType: "0",
          zqd: 2,
          payType: "",
          keyword: "", // 二维码、关键字
        },
        flowPlanForm: {
          token: "",
          shopId: "",
          shopName: "",
          productId: "",
          planName: "",
          goodsUrl: "",
          goodsTitle: "",
          shopType: "",
          goodsSeller: "",
          showMoney: "",
          payPerson: "",
          goodsAddress: "",
          goodsImg: "",
          goodsItems: [
            {
              keyword: "",
              entranceType: 1,
              taskNum: 1, //新增
              taskType: {
                1: 0,
                2: 0,
                3: 0,
                4: 0,
                5: 0,
                6: 0,
                7: 0,
                8: 0
              }
            }
          ],
          allotType: 1,
          planOver: 2,
          startTime: "",
          endTime: "",
          overTime: "",
          planTime: "",
          remark: "",
          placementArea: "",
          ageId: "99",
          sexId: "99",
          creditId: "99",
          modelId: "99",
          payType: "",
          zqdType: "0",
          zqd: 2
        },
        // 主宝贝验证规则
        goodsMainRules: {
          planName: [
            {required: true, message: "请输入计划名称", trigger: "blur"}
          ],
          shopId: [{required: true, message: "请选择店铺", trigger: "blur"}],
          goodsUrl: [
            {required: true, message: "请输入商品链接", trigger: "blur"}
          ],
          productId: [
            {required: true, message: "请输入商品id", trigger: "blur"}
          ],
          shopType: [
            {required: true, message: "请选择店铺种类", trigger: "blur"}
          ],
          goodsTitle: [
            {required: true, message: "请输入商品标题", trigger: "blur"}
          ],
          shopName: [
            {required: true, message: "请选择店铺名称", trigger: "blur"}
          ],
          entranceType: [
            {required: true, message: "请选择入口类型", trigger: "blur"}
          ],
          keyword: [
            {required: true, message: "请输入关键词", trigger: "blur"}
          ],
          taskNum: [
            {required: true, message: "请输入单量", trigger: "blur"}
          ],
          buyNum: [
            {required: true, message: "请输入每单拍几件", trigger: "blur"}
          ],
          payMoney: [
            {required: true, message: "请输入拍下单价", trigger: "blur"}
          ],
          sku: [
            {required: true, message: "请输入拍下规格", trigger: "blur"}
          ],
          showMoney: [
            {required: true, message: "请输入搜索展示价格", trigger: "blur"}
          ],
          payPerson: [
            {required: true, message: "请输入付款人数", trigger: "blur"}
          ],
        },
        // 副宝贝验证规则
        goodsRules: {
          goodsUrlSon: [
            {required: true, message: "请输入商品链接", trigger: "blur"}
          ],
          productIdSon: [
            {required: true, message: "请输入商品id", trigger: "blur"}
          ],
          goodsTitleSon: [
            {required: true, message: "请输入商品标题", trigger: "blur"}
          ],
          buyNumSon: [
            {required: true, message: "请输入每单拍几件", trigger: "blur"}
          ],
          payMoneySon: [
            {required: true, message: "请输入拍下单价", trigger: "blur"}
          ],
          skuSon: [
            {required: true, message: "请输入拍下规格", trigger: "blur"}
          ],
          showMoneySon: [
            {required: true, message: "请输入搜索展示价格", trigger: "blur"}
          ],
          goodsAddressSon: [
            {required: true, message: "请输入商品归属地", trigger: "blur"}
          ],
        },
        initShopNameList: [],// {name：前缀+店铺名称，type:店铺类型，id}
        shopNameList: [],// 店铺名称 <= initShopNameList
        platformNameObject: {// 店铺名前缀
          1: "淘宝",
          2: "天猫",
          3: "京东",
          4: "1688",
          13: "唯品会",
          15: "拼多多"
        },
        tagsList: {},// 接单设置 五项
        platformTypeList: [],// 店铺类型|店铺种类
        initPlatformTypeList: [
          {
            label: "淘宝",
            value: 1
          },
          {
            label: "天猫",
            value: 2
          },
          /*{
            label: "京东",
            value: 3
          },
          {
            label: "1688",
            value: 4
          },
          {
            label: "唯品会",
            value: 13
          },
          {
            label: "拼多多",
            value: 15
          }*/
        ],// 服务于 => platformTypeList
        uploadData: {
          area: "goods"
        },
        uploadQrcodeData: {
          area: "qrCode"
        },
        isWphUrl: false,// 是否展示 抓取商品信息 按钮
        isWphMainUrl: false,// 是否展示 抓取主商品信息 按钮
        isShowGoodsDialog: false,// 显示主宝贝模态框
        isShowGoodsDialogSon: false,// 显示副宝贝模态框
        goodsSelect: {// 请求查询接口的参数
          token: "",
          page: 1,
          pageSize: 100,
          shopId: "",
          shopType: "",
          productId: ""
        },
        goodsList: [],
        curSelectGoodsIndex: "",
        curSelectGoods: {},
        entranceTypeList: [
          {
            label: "关键词",
            value: 1
          },
          {
            label: "淘口令",
            value: 2
          },
          {
            label: "二维码",
            value: 3
          },
          {
            label: "直播",
            value: 4
          }
        ],
        entranceTypeName: {
          1: "关键词",
          2: "淘口令",
          3: "二维码",
          4: "视频链接"
        },
        curQrcodeIndex: 0,
        taskTypeList: [
          {
            list: [
              {
                type: 1,
                name: "浏览"
              },
              {
                type: 2,
                name: "浏览+关注"
              },
              {
                type: 3,
                name: "浏览+加购"
              },
              {
                type: 4,
                name: "浏览+收藏"
              }
            ]
          },
          {
            list: [
              {
                type: 5,
                name: "浏览+加购+关注"
              },
              {
                type: 6,
                name: "浏览+关注+收藏"
              },
              {
                type: 7,
                name: "浏览+加购+收藏"
              },
              {
                type: 8,
                name: "浏览+加购+关注+收藏"
              }
            ]
          }
        ],
        tabsList: [
          {
            type: 1,
            name: "平均分配"
          },
          {
            type: 2,
            name: "手动分配"
          },
          {
            type: 3,
            name: "指定时间"
          }
        ],// 发布时间设置类型
        setPlanTime: {// 发布时间设置
          startTime: "",// 起始时间
          endTime: "",// 结束时间
          overTime: ""// 计划终止时间
        },
        pickerOptions1: {
          disabledDate(time) {
            let curDate = new Date().getTime();
            let three = 6 * 24 * 3600 * 1000;
            let threeMonths = curDate + three;
            return (
              time.getTime() < Date.now() - 8.64e7 || time.getTime() > threeMonths
            );
          }
        },
        pickerOptions2: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
        totalAllotNum: 0,
        isForbidEditNum: false,
        intendOrderNum: 0,
        oldOverTime: "",
        remarkList: [],
        // 接单设置 start
        showSexArr: [1, 2, 13],// 筛选展示的类型： 区域 性别 年龄 机型
        showCreditArr: [1, 2],// 筛选展示的类型： 信用
        // 接单设置 end
        // 主宝贝问答设置 start
        showCheckContentArr: [1, 2],// 筛选展示的条件
        // 主宝贝问答设置 end
        // 预约增权单设置 start
        showZqdArr: [1, 2],
        // 预约增权单设置 end
        isShowAreaDialog: false,
        tagsDefaultPrice: [],// 价格标签数组
        serviceFeeList: [],// 服务于 => tagsDefaultPrice
        ageIdArr: ["99"],
        checkContent: "",
        checkContentStatus: false,// 展示 问答设置 的条件之一
        tkCheckType: 2,
        zqdTypeData: [
          {
            value: "0",
            label: "全部"
          },
          {
            value: "1",
            label: "一天内浏览过"
          },
          {
            value: "2",
            label: "两天内浏览过"
          },
          {
            value: "3",
            label: "三天内浏览过"
          },
          {
            value: "4",
            label: "一周内浏览过"
          }
        ],
        isIndeterminate: false,// 某项的地区是否全选（false全选 true全不选）
        provinceOpitons: [
          {
            area: "华东地区",
            province: ["北京市", "天津市", "河北省", "山西省", "内蒙古自治区"],
            checkedCities: [
              "北京市",
              "天津市",
              "河北省",
              "山西省",
              "内蒙古自治区"
            ],
            isIndeterminate: false,// 是否全选地区
            checkAll: true
          },
          {
            area: "东北地区",
            province: ["辽宁省", "吉林省", "黑龙江省"],
            checkedCities: ["辽宁省", "吉林省", "黑龙江省"],
            isIndeterminate: false,
            checkAll: true
          },
          {
            area: "华东地区",
            province: [
              "上海市",
              "江苏省",
              "浙江省",
              "安徽省",
              "福建省",
              "山东省"
            ],
            checkedCities: [
              "上海市",
              "江苏省",
              "浙江省",
              "安徽省",
              "福建省",
              "山东省"
            ],
            isIndeterminate: false,
            checkAll: true
          },
          {
            area: "华中地区",
            province: ["江西省", "河南省", "湖北省", "湖南省"],
            checkedCities: ["江西省", "河南省", "湖北省", "湖南省"],
            isIndeterminate: false,
            checkAll: true
          },
          {
            area: "华南地区",
            province: ["广东省", "广西壮族自治区", "海南省"],
            checkedCities: ["广东省", "广西壮族自治区", "海南省"],
            isIndeterminate: false,
            checkAll: true
          },
          {
            area: "西南地区",
            province: ["重庆市", "四川省", "贵州省", "云南省", "西藏自治区"],
            checkedCities: ["重庆市", "四川省", "贵州省", "云南省", "西藏自治区"],
            isIndeterminate: false,
            checkAll: true
          },
          {
            area: "西北地区",
            province: [
              "陕西省",
              "甘肃省",
              "青海省",
              "宁夏回族自治区",
              "新疆维吾尔族自治区"
            ],
            checkedCities: [
              "陕西省",
              "甘肃省",
              "青海省",
              "宁夏回族自治区",
              "新疆维吾尔族自治区"
            ],
            isIndeterminate: false,
            checkAll: true
          }
          // ,{
          //   area: '其他地区',
          //   province: [
          //     '香港特别行政区',
          //     '澳门特别行政区',
          //     '台湾省'
          //   ],
          //   checkedCities: [],
          //   isIndeterminate: false,
          //   checkAll: false
          // },
        ],// 地区参数
        checkAll: false,
        isShowPayPlanDialog: false,
        submitLoading: false,
        payPlanInfo: {
          planTime: "",
          capital: "",// 本金字符串显示
          commission: "",// 佣金
          commissionShow: "",// 副宝贝字符串显示
          copyCommission: "",// 副宝贝佣金
          otherService: {
            sex: {},
            age: {},
            model: {},
            credit: {},
            zqd: {}
          },
          freezeMoney: 0// 支付合计金额
        },
        originalShopNameList: [],// 店铺名称列表
        isUploadGoodsImg: false,
        isShowOtherService: false,
        planType: this.$route.query.type,
        planId: this.$route.query.id,
        userToken: window.localStorage.getItem("token"),
        merchantData: JSON.parse(window.localStorage.getItem("merchantConfig"))
      };
    },
    created() {
      this.getOneDragInfo()// 副宝贝数量限制及获取副宝贝佣金
      this.bindShop();
      if (this.creatPlanType == "sales") {
        if (
          !this.merchantData.shop_show_type ||
          this.merchantData.shop_show_type == null
        ) {
          this.platformTypeList = this.initPlatformTypeList;
        } else {
          let shopShowTypeArr = this.merchantData.shop_show_type.split(",");
          for (var i in this.initPlatformTypeList) {
            if (
              shopShowTypeArr.indexOf(
                this.initPlatformTypeList[i].value.toString()
              ) >= 0
            ) {
              this.platformTypeList.push(this.initPlatformTypeList[i]);
            }
          }
        }
      } else {
        this.platformTypeList = [
          {
            label: "淘宝",
            value: 1
          },
          {
            label: "天猫",
            value: 2
          }
        ];
      }
      this.getShopTagInfo();
      this.goodsSelect.token = this.userToken;
      this.searchGoodsData();
      this.initCurTime();
      this.getRemarkList();
      this.getServiceFeeList();
      if (this.creatPlanType == "sales") {
        this.getMerchantUserStatus();
      }
      this.salesPlanForm.token = this.userToken;
      if (this.planId) {
        this.getPlanDetail();
      }
    },
    watch: {
      //监听路由跳转
      $route: {
        handler: function (to, from) {
          if (to.path == "/plan/createDragPlan") {
            this.creatPlanType = "sales";
            this.entranceTypeName = {
              1: "关键词",
              2: "淘口令",
              3: "二维码",
              4: "视频链接",
              5: "下单入口"
            };
            this.salesPlanForm = this.salesPlanForm;
          } else {
            this.creatPlanType = "flow";
            this.entranceTypeName = {
              1: "关键词",
              2: "淘口令",
              3: "视频链接",
              4: "直播"
            };
            this.salesPlanForm = this.flowPlanForm;
          }
        },
        immediate: true
      },
      "setPlanTime.endTime": function (val) {
        if (this.salesPlanForm.allotType == 2 && !val) {
          this.setPlanTime.endTime = moment()
            .set("hour", 23)
            .set("minute", 59)
            .toDate()
            .getTime();
          this.changeManualAllocationOverTime();
        }
      },
      "setPlanTime.startTime": function (val) {
        if (this.salesPlanForm.allotType == 2 && !val) {
          this.setPlanTime.startTime = moment()
            .set("hour", 0)
            .set("minute", 0)
            .toDate()
            .getTime();
        }
      }
    },
    methods: {
      updateData() {
        this.$forceUpdate()
      },
      //===============公共================
      bindShop() {
        this.$isClick(true);
        apiIsBindShop({
          token: this.userToken
        })
          .then(res => {
            this.$isClick(false);
            if (res.code == -1) {
              this.$message.error("你尚未绑定店铺，请先前往绑定");
              setTimeout(() => {
                this.$router.push("/shopManage/shopManage");
              }, 1000);
            }
          })
          .catch(res => {
            this.$isClick(false);
            this.$message.error(res.msg);
          });
      },
      getMerchantUserStatus() {
        this.$isClick(true);
        apiMerchantUserStatus({
          token: this.userToken
        })
          .then(res => {
            this.$isClick(false);
            if (res.code == 1) {
              this.checkContentStatus =
                res.msg.check_content_status == 2 ? true : false;// check_content_status是否展示问答
              this.salesPlanForm.rebateType = res.msg.rebate_type;
              this.tkCheckType = res.msg.tk_check_type;
            }
          })
          .catch(res => {
            this.$isClick(false);
          });
      },
      // 副宝贝数量限制及获取副宝贝佣金
      getOneDragInfo() {
        apiOneDragInfo({
          token: this.userToken
        }).then(res => {
          if (res.code == 1) {
            // 赋值副宝贝金额
            this.payPlanInfo.copyCommission = res.msg.accessoryCommission;
            this.accessoryLimit = res.msg.accessoryLimit
          } else {
            this.$message.error(res.msg)
          }
        }).catch(res => {
          console.log(res)
        })
      },
      getServiceFeeList() {
        this.$isClick(true);
        apiGetServiceFeeList({
          token: this.userToken
        })
          .then(res => {
            this.$isClick(false);
            if (res.code == 1) {
              this.serviceFeeList = res.msg;
              this.platFormTypeChange();
            }
          })
          .catch(res => {
            this.$isClick(false);
          });
      },
      getRemarkList() {
        this.$isClick(true);
        apiGetRemarkList()
          .then(res => {
            this.$isClick(false);
            if (res.code == 1) {
              this.remarkList = res.msg;
            }
          })
          .catch(res => {
            this.$isClick(false);
          });
      },
      getShopTagInfo() {
        this.$isClick(true);
        apiShopTagInfo({
          token: this.userToken
        })
          .then(res => {
            this.$isClick(false);
            if (res.code == 1) {
              //店铺列表
              this.originalShopNameList = res.msg.shop_list;
              for (var i in res.msg.shop_list) {
                if (res.msg.shop_list[i].type == 1 || res.msg.shop_list[i].type == 2){
                  this.initShopNameList.push({
                    name:
                      this.platformNameObject[res.msg.shop_list[i].type] +
                      "-" +
                      res.msg.shop_list[i].name,
                    type: res.msg.shop_list[i].type,
                    id: res.msg.shop_list[i].id
                  });
                }
              }
              this.shopNameList = this.initShopNameList;
              //接单参数
              var arr = res.msg.tag_list;
              var tagNameArr = [
                "age_list",
                "sex_list",
                "model_list",
                "credit_list",
                "address_list"
              ];
              for (var i in arr) {
                for (var j in tagNameArr) {
                  if (i == j) {
                    this.$set(this.tagsList, tagNameArr[j], arr[i]);
                  }
                }
              }
            }
          })
          .catch(res => {
            this.$isClick(false);
          });
      },
      dataFilter(val) {
        this.salesPlanForm.shopId = val;
        if (val) {
          this.shopNameList = this.initShopNameList.filter(item => {
            if (
              !!~item.name.indexOf(val) ||
              !!~item.name.toUpperCase().indexOf(val.toUpperCase())
            ) {
              return true;
            }
          });
        } else {
          this.shopNameList = this.initShopNameList;
        }
      },
      //抓取链接信息
      changeGoodsUrl() {
        if (
          this.salesPlanForm.goodsUrl.indexOf("detail.tmall.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("item.taobao.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("taobao.com") != -1// ||
          // this.salesPlanForm.goodsUrl.indexOf("item.jd.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("item.m.jd.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("yangkeduo.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("detail.1688.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("pinduoduo.com") != -1
        ) {
          this.isWphMainUrl = false
        }/* else if (
          this.salesPlanForm.goodsUrl.indexOf("m.vip.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("detail.vip.com") != -1
        ) {
          this.isWphUrl = true;
          this.salesPlanForm.productId = this.salesPlanForm.goodsUrl
            .split("detail-")[1]
            .split(".html")[0];
        } else {
          this.isWphUrl = true;
        }*/
      },
      //抓取链接信息
      changeGoodsUrlSon(index) {
        if (
          this.salesPlanForm.goodsUrl.indexOf("detail.tmall.com") != -1 ||
          this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("item.taobao.com") != -1 ||
          this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("taobao.com") != -1// ||
          // this.salesPlanForm.goodsUrl.indexOf("item.jd.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("item.m.jd.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("yangkeduo.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("detail.1688.com") != -1 ||
          // this.salesPlanForm.goodsUrl.indexOf("pinduoduo.com") != -1
        ) {
          this.isWphUrl = false
        }/* else if (
          this.salesPlanForm.goodsUrl.indexOf("m.vip.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("detail.vip.com") != -1
        ) {
          this.isWphUrl = true;
          this.salesPlanForm.productId = this.salesPlanForm.goodsUrl
            .split("detail-")[1]
            .split(".html")[0];
        } else {
          this.isWphUrl = true;
        }*/
      },
      goodsInfo() {
        if (
          this.salesPlanForm.goodsUrl.indexOf("detail.tmall.com") >= 0
          || this.salesPlanForm.goodsUrl.indexOf("item.taobao.com") >= 0
        ) {
          this.$loading.show("抓取中");
          if (this.salesPlanForm.goodsUrl != "") {
            if (
              this.salesPlanForm.goodsUrl.indexOf("detail.tmall.com") != -1 ||
              this.salesPlanForm.goodsUrl.indexOf("item.taobao.com") != -1
              // this.salesPlanForm.goodsUrl.indexOf("item.jd.com") != -1 ||
              // this.salesPlanForm.goodsUrl.indexOf("item.m.jd.com") != -1 ||
              // this.salesPlanForm.goodsUrl.indexOf("yangkeduo.com") != -1 ||
              // this.salesPlanForm.goodsUrl.indexOf("detail.1688.com") != -1 ||
              // this.salesPlanForm.goodsUrl.indexOf("pinduoduo.com") != -1
            ) {
              this.isWphMainUrl = false// 是否展示 抓取商品信息 按钮
              this.getProductId();// 抓取商品及赋值链接
              apiGetGoodsInfo({
                goodsUrl: escape(this.salesPlanForm.goodsUrl),
                token: this.userToken
              })
                .then(res => {
                  this.$loading.hide();
                  if (res.code == 1) {
                    this.isForbidRevise = true;//抓取商品信息成功后禁止修改信息
                    // 主宝贝
                    this.salesPlanForm.goodsTitle = res.msg.name;// 商品标题
                    this.salesPlanForm.goodsSeller = res.msg.seller_name;// 掌柜昵称
                    this.salesPlanForm.shopName = res.msg.shop_name;// 抓取的店铺名称
                    this.salesPlanForm.coName = res.msg.co_name;// 掌柜昵称
                    this.salesPlanForm.shopType = res.msg.shop_type;// 店铺种类
                    this.platFormTypeChange();
                    // this.salesPlanForm.goodsImg = res.msg.goods_img;
                    this.salesPlanForm.goodsMainImg = res.msg.goods_img;// 商品主图
                    this.salesPlanForm.productId = res.msg.product_id;// 商品id
                    return this.$message.success("抓取商品信息成功");
                  } else {
                    this.isForbidRevise = false;
                    this.$message.error(res.msg);
                  }
                })
                .catch(res => {
                  console.log(res)
                  this.$loading.hide();
                  this.$message.error(res.msg);
                });
            }/* else if (
            this.salesPlanForm.goodsUrl.indexOf("m.vip.com") != -1 ||
            this.salesPlanForm.goodsUrl.indexOf("detail.vip.com") != -1
          ) {
            this.$loading.hide();
            this.isWphUrl = true;
            this.salesPlanForm.goodsTitle = "";
            this.salesPlanForm.goodsSeller = "";
            this.salesPlanForm.shopName = "";
            this.salesPlanForm.shopType = "";
          }*/
          } else {
            this.$loading.hide();
            return this.$message.error("请输入商品链接在抓取");
          }
        } else {
          this.$message.error("只能抓取淘宝或天猫商品");
          return
        }

      },
      goodsInfoSon(index) {
        if (
          this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("detail.tmall.com") >= 0
          ||this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("item.taobao.com") >= 0) {
          this.$loading.show("抓取中");
          if (this.salesPlanForm.goodsItems[index].goodsUrlSon != "") {
            if (
              this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("detail.tmall.com") != -1 ||
              this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("item.taobao.com") != -1
            ) {
              this.isWphUrl = false// 是否展示 抓取商品信息 按钮
              this.getProductIdSon(index);// 抓取商品及赋值链接
              apiGetGoodsInfo({
                goodsUrl: escape(this.salesPlanForm.goodsItems[index].goodsUrlSon),
                token: this.userToken
              })
                .then(res => {
                  this.$loading.hide();
                  if (res.code == 1) {
                    this.isForbidRevise = true;//抓取商品信息成功后禁止修改信息
                    // 副宝贝
                    this.salesPlanForm.goodsItems[index].goodsTitleSon = res.msg.name;// 商品标题
                    this.salesPlanForm.goodsItems[index].goodsSellerSon = res.msg.seller_name;// 掌柜昵称
                    this.salesPlanForm.goodsItems[index].shopNameSon = res.msg.shop_name;// 抓取的店铺名称
                    this.salesPlanForm.goodsItems[index].coNameSon = res.msg.co_name;// 掌柜昵称
                    this.salesPlanForm.goodsItems[index].shopTypeSon = res.msg.shop_type;// 店铺种类
                    this.salesPlanForm.goodsItems[index].goodsImg = res.msg.goods_img;// 商品主图
                    this.salesPlanForm.goodsItems[index].productIdSon = res.msg.product_id;// 商品id
                    return this.$message.success("抓取商品信息成功");
                  } else {
                    this.isForbidRevise = false;
                    this.$message.error(res.msg);
                  }
                })
                .catch(res => {
                  this.$loading.hide();
                  this.$message.error(res.msg);
                });
            }
          } else {
            this.$loading.hide();
            return this.$message.error("请输入商品链接在抓取");
          }
        } else {
          this.$message.error("只能抓取淘宝或天猫商品");
          return
        }

      },
      getProductId() {
        /*if (
          this.salesPlanForm.goodsUrl.indexOf("item.jd.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("item.m.jd.com") != -1
        ) {
          let urlArr = this.salesPlanForm.goodsUrl.split(".html")[0];
          let urlArr1 = urlArr.split("/");
          this.salesPlanForm.productId = urlArr1[urlArr1.length - 1];
        }*/
        if (
          this.salesPlanForm.goodsUrl.indexOf("detail.tmall.com") != -1 ||
          this.salesPlanForm.goodsUrl.indexOf("item.taobao.com") != -1
        ) {
          this.salesPlanForm.productId = this.getRequestParam(
            this.salesPlanForm.goodsUrl,
            "id"
          );
        }
        /*if (this.salesPlanForm.goodsUrl.indexOf("yangkeduo.com") != -1) {
          this.salesPlanForm.productId = this.getRequestParam(
            this.salesPlanForm.goodsUrl,
            "goods_id"
          );
        }
        if (this.salesPlanForm.goodsUrl.indexOf("detail.1688.com") != -1) {
          let urlArr = this.salesPlanForm.goodsUrl.split(".html")[0];
          let urlArr1 = urlArr.split("/");
          this.salesPlanForm.productId = urlArr1[urlArr1.length - 1];
        }
        if (this.salesPlanForm.goodsUrl.indexOf("pinduoduo.com") != -1) {
          this.salesPlanForm.productId = this.getRequestParam(
            this.salesPlanForm.goodsUrl,
            "gid"
          );
        }*/
      },
      getProductIdSon(index) {
        if (
          this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("detail.tmall.com") != -1 ||
          this.salesPlanForm.goodsItems[index].goodsUrlSon.indexOf("item.taobao.com") != -1
        ) {
          this.salesPlanForm.goodsItems[index].productIdSon = this.getRequestParam(
            this.salesPlanForm.goodsItems[index].goodsUrlSon,
            "id"
          );
        }
      },
      getRequestParam(url, name) {
        var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)", "i");
        var r = url.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
      },
      //选择商品
      showSelectGoodsDialog() {
        this.curSelectGoods = {};
        this.curSelectGoodsIndex = "";
        this.goodsSelect = {
          token: this.userToken,
          page: 1,
          pageSize: 100,
          shopId: "",
          shopType: "",
          productId: ""
        };
        this.isShowGoodsDialog = true;
      },
      showSelectGoodsDialogSon(index) {
        this.sonIndex = index
        this.curSelectGoods = {};
        this.curSelectGoodsIndex = "";
        this.goodsSelect = {
          token: this.userToken,
          page: 1,
          pageSize: 100,
          shopId: "",
          shopType: "",
          productId: ""
        };
        this.isShowGoodsDialogSon = true;
      },
      searchGoodsData() {
        this.$isClick(true);
        apiMerchantGoods(this.goodsSelect)
          .then(res => {
            this.$isClick(false);
            if (res.code == 1) {
              this.goodsList = res.msg.res;
            } else {
              this.$message.error(res.msg);
            }
          })
          .catch(res => {
            this.$isClick(false);
            this.$message.error(res.msg);
          });
      },
      selectGoods(item, index) {
        this.curSelectGoods = item;
        this.curSelectGoodsIndex = index;
      },
      sumbitSelectGoods(item) {
        console.log(item.goods_url)
        if (
          item.goods_url.indexOf("detail.tmall.com") >= 0
          || item.goods_url.indexOf("item.taobao.com") >= 0
          || item.goods_url.indexOf("taobao.com") >= 0
        ) {
          this.isForbidRevise = true;
          this.salesPlanForm.goodsTitle = item.goods_title;
          this.salesPlanForm.goodsSeller = item.selle_name;
          this.salesPlanForm.shopName = item.shop_name;
          this.salesPlanForm.shopType = item.shop_type;
          this.salesPlanForm.goodsUrl = item.goods_url;
          this.platFormTypeChange();
          this.salesPlanForm.goodsMainImg = item.goods_img;
          this.salesPlanForm.productId = item.product_id;
          this.isShowGoodsDialog = false;
          this.isShowGoodsDialogSon = false;
        } else {
          this.$message.error("只能选择淘宝或天猫商品");
          return
        }

      },
      sumbitSelectGoodsSon(item) {
        if (
          item.goods_url.indexOf("detail.tmall.com") >= 0
          || item.goods_url.indexOf("item.taobao.com") >= 0
          || item.goods_url.indexOf("taobao.com") >= 0) {
          this.isForbidRevise = true;
          this.salesPlanForm.goodsItems[this.sonIndex].goodsTitleSon = item.goods_title;
          this.salesPlanForm.goodsItems[this.sonIndex].goodsSellerSon = item.selle_name;
          this.salesPlanForm.goodsItems[this.sonIndex].shopNameSon = item.shop_name;
          this.salesPlanForm.goodsItems[this.sonIndex].shopTypeSon = item.shop_type;
          this.salesPlanForm.goodsItems[this.sonIndex].goodsUrlSon = item.goods_url;
          this.salesPlanForm.goodsItems[this.sonIndex].goodsImg = item.goods_img;
          this.salesPlanForm.goodsItems[this.sonIndex].productIdSon = item.product_id;
          this.isShowGoodsDialogSon = false;
        } else {
          this.$message.error("只能选择淘宝或天猫商品");
          return
        }

      },
      // 获取接单设置标签对应价格及设置入口类型
      platFormTypeChange() {
        this.setEntranceType();
        //获取接单设置标签对应价格
        if (this.salesPlanForm.shopType == 1) {
          for (let i in this.serviceFeeList.service_fee_tb) {
            if (this.serviceFeeList.service_fee_tb[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_tb[i]);
            }
          }
        }
        if (this.salesPlanForm.shopType == 2) {
          for (let i in this.serviceFeeList.service_fee_tm) {
            if (this.serviceFeeList.service_fee_tm[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_tm[i]);
            }
          }
        }
        if (this.salesPlanForm.shopType == 3) {
          for (let i in this.serviceFeeList.service_fee_jd) {
            if (this.serviceFeeList.service_fee_jd[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_jd[i]);
            }
          }
        }
        if (this.salesPlanForm.shopType == 4) {
          for (let i in this.serviceFeeList.service_fee_albb) {
            if (this.serviceFeeList.service_fee_albb[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_albb[i]);
            }
          }
        }
        if (this.salesPlanForm.shopType == 13) {
          for (let i in this.serviceFeeList.service_fee_wph) {
            if (this.serviceFeeList.service_fee_wph[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_wph[i]);
            }
          }
        }
        if (this.salesPlanForm.shopType == 15) {
          for (let i in this.serviceFeeList.service_fee_pdd) {
            if (this.serviceFeeList.service_fee_pdd[i].pay_type == 2) {
              this.tagsDefaultPrice.push(this.serviceFeeList.service_fee_pdd[i]);
            }
          }
        }
      },
      // 设置 入口类型 展示字段
      setEntranceType() {
        if (this.salesPlanForm.shopType == 1 || this.salesPlanForm.shopType == 2) {
          if (this.creatPlanType == "sales") {
            this.entranceTypeList = [
              {
                label: "关键词",
                value: 1
              },
              {
                label: "淘口令",
                value: 2
              },
              {
                label: "二维码",
                value: 3
              },
              {
                label: "直播",
                value: 4
              },
              {
                label: "其他",
                value: 5
              }
            ];
          } else {
            this.entranceTypeList = [
              {
                label: "关键词",
                value: 1
              },
              {
                label: "淘口令",
                value: 2
              },
              {
                label: "二维码",
                value: 3
              },
              {
                label: "直播",
                value: 4
              }
            ];
          }
        } else {
          this.entranceTypeList = [
            {
              label: "关键词",
              value: 1
            },
            {
              label: "二维码",
              value: 3
            },
            {
              label: "直播",
              value: 4
            },
            {
              label: "其他",
              value: 5
            }
          ];
        }
      },
      handleAvatarSuccess(res, file) {
        this.salesPlanForm.goodsImg = res.msg;
        this.isUploadGoodsImg = true;
        this.$message.success("上传成功");
      },
      beforeAvatarUpload(file) {
        const isLt2M = file.size / 1024 / 1024 < 10;
        if (!isLt2M) {
          this.$message.error("上传商品图片大小不能超过 10MB!");
        }
        this.uploadImgStatus = 1;
        return isLt2M;
      },
      entranceTypeChange(val, item) {
        this.$set(item, "keyword", "");
        this.$set(item, "entranceType", val);
        this.$forceUpdate(); //强制刷新
      },
      expressionFilter(e) {
        const newKeyword = e.keyword.replace(
          /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g,
          ""
        );
        this.$set(e, "keyword", newKeyword);
      },
      inputUpdate() {
        this.$forceUpdate();
      },
      cutTask(index) {
        for (var i in this.salesPlanForm.goodsItems) {
          if (index == i) {
            this.salesPlanForm.goodsItems.splice(i, 1);
          }
        }
      },
      addTask() {
        if (this.salesPlanForm.goodsItems.length == this.accessoryLimit) {
          return this.$message({
            message: '附宝贝数量已达限制',
            type: 'warning'
          });
        }
        let task = {};
        if (this.creatPlanType == "sales") {
          task = {
            goodsUrlSon: "",
            productIdSon: "",
            goodsTitleSon: "",
            buyNumSon: "",
            payMoneySon: "",
            skuSon: "",
            goodsImg: "",
            showMoneySon: "",
            goodsAddressSon: ""
          };
          /*task = {
            keyword: "",
            payMoney: "",
            sku: "",
            entranceType: 1,
            taskNum: "1",
            buyNum: "1"
          };*/
        } else {
          task = {
            keyword: "",
            entranceType: 1,
            taskNum: "1", //新增
            taskType: {
              1: 0,
              2: 0,
              3: 0,
              4: 0,
              5: 0,
              6: 0,
              7: 0,
              8: 0
            }
          };
        }
        this.salesPlanForm.goodsItems.push(task);
      },
      //发布时间设置
      initCurTime() {
        var now = new Date();
        this.setPlanTime.startTime = now.getTime();
        this.setPlanTime.endTime =
          new Date(new Date().toLocaleDateString()).getTime() +
          24 * 60 * 60 * 1000 -
          1;

        if (this.salesPlanForm.allotType == 3) {
          this.setPlanTime.endTime = "";
        }
      },
      changeTimeTab(type) {
        if (this.isForbidModify) {
          return;
        }
        this.salesPlanForm.allotType = type;
        this.initCurTime();// 发布时间设置
        if (this.salesPlanForm.allotType == 2) {
          this.selectDate();
          this.salesPlanForm.planOver = 1;
          let date = new Date(this.setPlanTime.startTime); //new Date(value*1000);根据时间戳格式进行选择乘1000或否
          let timeDate;
          let Y = date.getFullYear() + "-";
          let M =
            (date.getMonth() + 1 < 10
              ? "0" + (date.getMonth() + 1)
              : date.getMonth() + 1) + "-";
          let D =
            (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
          timeDate = Y + M + D + "23:29:59";
          this.setPlanTime.endTime = new Date(timeDate).getTime();
          let overTimeDate = Y + M + D + "23:30:00";
          this.setPlanTime.overTime = new Date(overTimeDate).getTime();
          this.oldOverTime = JSON.parse(
            JSON.stringify(this.setPlanTime.overTime)
          );
        } else {
          this.salesPlanForm.planOver = 2;
          this.setPlanTime.overTime = "";
        }
      },
      changeStartTime() {
        if (this.salesPlanForm.planOver == 1) {
          if (this.setPlanTime.overTime - this.setPlanTime.startTime < 0) {
            return this.$message.error("终止时间不能小于开始时间");
          }
        }
      },
      changeDate() {
        if (this.setPlanTime.startTime - this.setPlanTime.endTime > 0) {
          this.$message.error("开始时间不能大于结束时间!");
          var now = new Date();
          this.setPlanTime.startTime = now.getTime();
          this.setPlanTime.endTime =
            new Date(new Date().toLocaleDateString()).getTime() +
            24 * 60 * 60 * 1000 -
            1;
          return;
        }
        if (this.salesPlanForm.planOver == 1) {
          if (this.setPlanTime.overTime - this.setPlanTime.endTime < 0) {
            this.setPlanTime.endTime =
              new Date(new Date().toLocaleDateString()).getTime() +
              24 * 60 * 60 * 1000 -
              1;
            return this.$message.error("终止时间不能小于结束时间");
          }
        }
      },
      changeOverTime(val) {
        if (this.salesPlanForm.allotType == 2) {
          if (this.setPlanTime.overTime < this.setPlanTime.endTime) {
            this.setPlanTime.overTime = moment(this.setPlanTime.endTime)
              .toDate()
              .getTime();
            return this.$message.error("终止时间不能小于结束时间");
          }
          let newOverTime = JSON.parse(JSON.stringify(this.setPlanTime.overTime));
          newOverTime = newOverTime / 1000;
          let flag = false;
          Object.keys(this.salesPlanForm.planTime).forEach((item, index) => {
            for (var i in this.salesPlanForm.planTime[item]) {
              if (newOverTime - parseInt(i) < 0) {
                if (this.salesPlanForm.planTime[item][i] > 0) {
                  this.$message.error(
                    "该终止时间后面有分配数，请先置为0在设置终止时间"
                  );
                  this.setPlanTime.overTime = JSON.parse(
                    JSON.stringify(this.oldOverTime)
                  );
                  flag = true;
                  return;
                }
              }
            }
          });
          if (!flag) {
            this.oldOverTime = JSON.parse(
              JSON.stringify(this.setPlanTime.overTime)
            );
          }
        } else {
          if (this.setPlanTime.overTime - this.setPlanTime.startTime < 0) {
            this.setPlanTime.overTime = "";
            return this.$message.error("终止时间不能小于开始时间");
          }
        }
      },
      changeManualAllocationTime(val) {
        // let date = new Date(this.setPlanTime.startTime); //new Date(value*1000);根据时间戳格式进行选择乘1000或否
        // let timeDate;
        // let Y = date.getFullYear() + '-';
        // let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        // let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
        //
        // let curCheckTime = this.setPlanTime.startTime / 1000
        // let curCheckDay = this.getDateOfDay(curCheckTime);
        // let today = new Date();
        // if(curCheckDay != today.getDate()) {
        //   let startTimeDate = Y + M + D + '00:00:00';
        //   this.setPlanTime.startTime = new Date(startTimeDate).getTime()
        // }
        if (val) {
          if (
            moment(this.setPlanTime.startTime).isBefore(
              moment(this.setPlanTime.endTime)
            )
          )
            return val;
          this.$message.error("开始时间不能大于结束时间");
          this.setPlanTime.startTime = moment(this.setPlanTime.endTime).add(
            -1,
            "days"
          );
        } else {
          // this.setPlanTime.startTime = moment().set('hour', 0).set('minute', 0).toDate().getTime()
        }

        // timeDate = Y + M + D + '23:29:59';
        // this.setPlanTime.endTime = new Date(timeDate).getTime()
        // let overTimeDate = Y + M + D + '23:30:00';
        // this.setPlanTime.overTime = new Date(overTimeDate).getTime()
        // this.oldOverTime = JSON.parse(JSON.stringify(this.setPlanTime.overTime))
      },
      changeManualAllocationEndTime(val) {
        if (val) {
          this.changeManualAllocationOverTime();
          if (moment(this.setPlanTime.startTime).isBefore(moment(val)))
            return val;
          this.setPlanTime.endTime = moment(this.setPlanTime.startTime).add(
            1,
            "days"
          );
          this.changeManualAllocationOverTime();
          this.$message.error("开始时间不能大于结束时间");
        } else {
          // this.setPlanTime.endTime = moment().set('hour', 23).set('minute', 59).toDate().getTime()
          // this.changeManualAllocationOverTime()
          // console.log(this.setPlanTime.endTime)
          // this.setPlanTime.endTime = new Date().getTime()
        }
      },
      changeManualAllocationOverTime() {
        this.setPlanTime.overTime = moment(this.setPlanTime.endTime)
          .toDate()
          .getTime();
        this.oldOverTime = JSON.parse(JSON.stringify(this.setPlanTime.overTime));
      },
      selectDate() {
        this.$forceUpdate();
        if (this.setPlanTime.startTime == "" && this.setPlanTime.endTime == "") {
          return;
        }
        // =============
        var startTimestamp = this.setPlanTime.startTime / 1000;
        var endTimestamp = this.setPlanTime.endTime / 1000;
        //获取哪天
        var startTimeOfDay = this.getDateOfDay(startTimestamp);
        var endTimeOfDay = this.getDateOfDay(endTimestamp);
        //获取开始时间在哪个小时
        var startTimeOfHours = this.getDateOfHours(startTimestamp);
        var endTimeOfHours = this.getDateOfHours(endTimestamp);
        //获取第几年
        var startTimeOYear = this.getDateOfYear(startTimestamp);
        var endTimeOYear = this.getDateOfYear(endTimestamp);
        //获取第几月
        var startTimeOfMonth = this.getDateOfMonth(startTimestamp);
        var endTimeOfMonth = this.getDateOfMonth(endTimestamp);
        //开始时间当天的小时差
        var curPeriod = 24 - startTimeOfHours;
        var timeJosn = {};
        var curTimeKey =
          startTimeOYear +
          "-" +
          startTimeOfMonth +
          "-" +
          startTimeOfDay +
          " " +
          startTimeOfHours +
          ":" +
          "00:00";

        var newCurTimeKey = this.dateToUnix(curTimeKey);

        //开始时间到结束时间相差几天
        var dayNum = endTimeOfDay - startTimeOfDay;
        //当dayNum=0时，开始时间跟结束时间在同一天

        //判断开始时间和结束时间是否在同一个月
        if (startTimeOfMonth == endTimeOfMonth) {
          //判断开始时间和结束时间是否在同一天
          if (dayNum == 0) {
            timeJosn[newCurTimeKey] = {};
            var now = new Date();
            var hour = now.getHours();
            let newPeriod = 24 - hour;
            if (startTimeOfDay != now.getDate()) {
              for (var i = 0; i < curPeriod; i++) {
                var date =
                  startTimeOYear +
                  "-" +
                  startTimeOfMonth +
                  "-" +
                  startTimeOfDay +
                  " " +
                  (parseInt(startTimeOfHours) + i) +
                  ":" +
                  "00:00";
                timeJosn[newCurTimeKey][this.dateToUnix(date)] = 0;
              }
            } else {
              for (var i = 1; i < newPeriod; i++) {
                var date =
                  startTimeOYear +
                  "-" +
                  startTimeOfMonth +
                  "-" +
                  startTimeOfDay +
                  " " +
                  (parseInt(hour) + i) +
                  ":" +
                  "00:00";
                timeJosn[newCurTimeKey][this.dateToUnix(date)] = 0;
              }
            }
          } else {
            //当开始时间跟结束时间相差一天以上，就要把当天跟后面几天合在一起
            timeJosn[newCurTimeKey] = {};
            for (var i = 1; i < curPeriod; i++) {
              var date =
                startTimeOYear +
                "-" +
                startTimeOfMonth +
                "-" +
                startTimeOfDay +
                " " +
                (parseInt(startTimeOfHours) + i) +
                ":" +
                "00:00";
              timeJosn[newCurTimeKey][this.dateToUnix(date)] = 0;
            }
            //第二天开始
            for (var i = 0; i < dayNum; i++) {
              var timeKey =
                startTimeOYear +
                "-" +
                startTimeOfMonth +
                "-" +
                (parseInt(startTimeOfDay) + (i + 1)) +
                " " +
                startTimeOfHours +
                ":" +
                "00:00";
              var newTimeKey = this.dateToUnix(timeKey);
              timeJosn[newTimeKey] = {};
              for (var j = 0; j < 24; j++) {
                var date =
                  startTimeOYear +
                  "-" +
                  startTimeOfMonth +
                  "-" +
                  (parseInt(startTimeOfDay) + (i + 1)) +
                  " " +
                  j +
                  ":" +
                  "00:00";
                timeJosn[newTimeKey][this.dateToUnix(date)] = 0;
              }
            }
          }
        } else {
          //开始时间那个月的总天数
          var startTimeOfMonthAllDay = this.getMonDay(this.setPlanTime.startTime);
          //结束时间那个月的第几天
          var endtDateOfNowDay = this.getNowDay(this.setPlanTime.endTime);

          timeJosn[newCurTimeKey] = {};
          for (var i = 1; i < curPeriod; i++) {
            var date =
              startTimeOYear +
              "-" +
              startTimeOfMonth +
              "-" +
              startTimeOfDay +
              " " +
              (parseInt(startTimeOfHours) + i) +
              ":" +
              "00:00";
            timeJosn[newCurTimeKey][this.dateToUnix(date)] = 0;
          }
          var curDayNum = startTimeOfMonthAllDay - startTimeOfDay;
          for (var i = 0; i < curDayNum; i++) {
            var timeKey =
              startTimeOYear +
              "-" +
              startTimeOfMonth +
              "-" +
              (parseInt(startTimeOfDay) + (i + 1)) +
              " " +
              startTimeOfHours +
              ":" +
              "00:00";
            var newTimeKey = this.dateToUnix(timeKey);
            timeJosn[newTimeKey] = {};
            for (var j = 0; j < 24; j++) {
              var date =
                startTimeOYear +
                "-" +
                startTimeOfMonth +
                "-" +
                (parseInt(startTimeOfDay) + (i + 1)) +
                " " +
                j +
                ":" +
                "00:00";
              timeJosn[newTimeKey][this.dateToUnix(date)] = 0;
            }
          }
          //获取下个月的
          for (var i = 0; i < endtDateOfNowDay; i++) {
            var timeKey =
              endTimeOYear +
              "-" +
              endTimeOfMonth +
              "-" +
              (i + 1) +
              " " +
              endTimeOfHours +
              ":" +
              "00:00";
            var newTimeKey = this.dateToUnix(timeKey);
            timeJosn[newTimeKey] = {};
            for (var j = 0; j < 24; j++) {
              var date =
                endTimeOYear +
                "-" +
                endTimeOfMonth +
                "-" +
                (i + 1) +
                " " +
                j +
                ":" +
                "00:00";
              timeJosn[newTimeKey][this.dateToUnix(date)] = 0;
            }
          }
        }

        this.salesPlanForm.planTime = timeJosn;
        this.totalAllocation();
      },
      totalAllocation() {
        let totalNumber = 0;
        Object.keys(this.salesPlanForm.planTime).forEach(item => {
          Object.keys(this.salesPlanForm.planTime[item]).forEach(ite => {
            totalNumber += this.salesPlanForm.planTime[item][ite];
          });
        });
        this.totalAllotNum = totalNumber;
      },

      countIntendOrderNum() {
        var ordNumber = 0;
        ordNumber += parseInt(this.salesPlanForm.taskNum);
        /*let number = 0;
        this.salesPlanForm.goodsItems.forEach((item, index) => {
          ordNumber += parseInt(item.taskNum);
          for (const i in item.taskType) {
            number += parseInt(item.taskType[i]);
          }
        });*/
        this.intendOrderNum = ordNumber;
        // this.trafficOrderNum = number;
        if (this.creatPlanType === "sales") {
          return ordNumber;
        }/* else {
          return number;
        }*/
      },
      changeAllotNum(timeItem, itemKey) {
        this.totalAllocation();
        if (this.creatPlanType === "sales") {
          if (this.totalAllotNum > this.intendOrderNum) {
            this.isForbidEditNum = true;
            this.$nextTick(() => {
              this.$set(timeItem, itemKey, 0);
              this.totalAllocation();
            });
            this.$message.error("分配数不能超过计划中的单数!");
          } else {
            this.isForbidEditNum = false;
          }
        } else {
          if (this.totalAllotNum > this.trafficOrderNum) {
            this.isForbidEditNum = true;
            this.$nextTick(() => {
              this.$set(timeItem, itemKey, 0);
              this.totalAllocation();
            });
            this.$message.error("分配数不能超过计划中的单数!");
          } else {
            this.isForbidEditNum = false;
          }
        }

        let newOverTime = JSON.parse(JSON.stringify(this.setPlanTime.overTime));
        newOverTime = newOverTime / 1000;
        if (newOverTime - parseInt(itemKey) < 0) {
          this.isForbidEditNum = true;
          this.$nextTick(() => {
            this.$set(timeItem, itemKey, 0);
            this.totalAllocation();
          });
          this.$message.error("不能在终止时间后进行分配");
        }
        setTimeout(() => {
          this.isForbidEditNum = false;
        }, 5000);
      },
      clickRemarkText(content) {
        if (this.salesPlanForm.remark.length >= 150) {
          return;
        }
        this.salesPlanForm.remark += content + ";";
      },

      dateToUnix(string) {
        var f = string.split(" ", 2);
        var d = (f[0] ? f[0] : "").split("-", 3);
        var t = (f[1] ? f[1] : "").split(":", 3);
        return (
          new Date(
            parseInt(d[0], 10) || null,
            (parseInt(d[1], 10) || 1) - 1,
            parseInt(d[2], 10) || null,
            parseInt(t[0], 10) || null,
            parseInt(t[1], 10) || null,
            parseInt(t[2], 10) || null
          ).getTime() / 1000
        );
      },
      getNowDay(mydate) {
        var d = new Date(mydate);
        return d.getDate();
      },
      //获取当月总共几天
      getMonDay(mydate) {
        var d = new Date(mydate);
        //d.getMonth()+1月份索引从0开始,天数索引从1开始，第0天即代表最后一天
        var allDays = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
        return allDays;
      },
      //获取小时
      getDateOfHours(val) {
        var date = new Date(val * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var h = date.getHours();
        return h;
      },
      //获取月
      getDateOfMonth(val) {
        var date = new Date(val * 1000);
        var m =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        return m;
      },
      //获取天
      getDateOfDay(val) {
        var date = new Date(val * 1000);
        var d = date.getDate();
        return d;
      },
      getDateOfYear(val) {
        var date = new Date(val * 1000);
        var y = date.getFullYear();
        return y;
      },
      formatDate(now) {
        let year = now.getFullYear();
        let month = now.getMonth() + 1;
        let date = now.getDate();
        let hour = now.getHours();
        let minute = now.getMinutes();
        let second = now.getSeconds();
        return year + "." + month + "." + date;
      },

      //取月日
      getMonthAndDay(time) {
        var date = new Date(time * 1000);
        var m =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        var d = date.getDate();
        return m + "-" + d;
      },
      //-----接单设置-----
      //----地区 start---
      showAreaDialog() {
        this.isShowAreaDialog = true;
      },
      // 选择区域 关闭全选或开启全选
      handleCheckAllChange(value, item) {
        item.checkedCities = value ? item.province : [];
        item.isIndeterminate = false;
        var flag = true;
        for (var i in this.provinceOpitons) {
          if (!this.provinceOpitons[i].checkAll) {
            flag = false;
          }
        }
        this.isIndeterminate = flag == false ? true : false;
        this.checkAll = flag == false ? false : true;
      },
      // 检测 选择区域 某项是否全选
      handleCheckedProvinceChange(value, item) {
        let checkedCount = value.length;
        item.checkAll = checkedCount === item.province.length;
        item.isIndeterminate =
          checkedCount > 0 && checkedCount < item.province.length;
      },
      /*selectAll() {
        this.checkAll != this.checkAll;
        if (this.checkAll) {
          for (var i in this.provinceOpitons) {
            this.provinceOpitons[i].checkedCities = this.provinceOpitons[
              i
              ].province;
            this.provinceOpitons[i].isIndeterminate = false;
            this.provinceOpitons[i].checkAll = true;
          }
          this.isIndeterminate = false;
        } else {
          for (var i in this.provinceOpitons) {
            this.provinceOpitons[i].checkedCities = [];
            this.provinceOpitons[i].isIndeterminate = false;
            this.provinceOpitons[i].checkAll = false;
          }
        }
      },*/
      // 拼接并保存 选择区域 选项的值
      saveAreaData() {
        this.salesPlanForm.placementArea = "";
        var isSelectAll = false;
        for (var i in this.provinceOpitons) {
          if (!this.provinceOpitons[i].checkAll) {
            isSelectAll = true;
          }

          if (this.provinceOpitons[i].checkedCities.length > 0) {
            this.salesPlanForm.placementArea +=
              this.provinceOpitons[i].checkedCities.join(",") + ",";
          }
        }
        this.salesPlanForm.placementArea = isSelectAll
          ? this.salesPlanForm.placementArea.substring(
            0,
            this.salesPlanForm.placementArea.length - 1
          )
          : "";

        this.isShowAreaDialog = false;
      },
      //----地区 end---
      //----性别 start---
      // 获取标签默认价格
      getTagsDefaultPrice(title) {
        for (let i in this.tagsDefaultPrice) {
          if (this.tagsDefaultPrice[i].title == title) {
            return this.tagsDefaultPrice[i].default_price;
          }
        }
      },
      changeAge(val) {
        if (val.length > 1) {
          if (val.indexOf("99") >= 0) {
            for (var i in this.ageIdArr) {
              if (this.ageIdArr[i] == "99") {
                this.ageIdArr.splice(i, 1);
              }
            }
          }
        }
        this.salesPlanForm.ageId = this.ageIdArr.join(",");
      },
      formValidate() {
        for (var i in this.originalShopNameList) {
          if (this.salesPlanForm.shopId == this.originalShopNameList[i].id) {
            if (this.salesPlanForm.shopType != this.originalShopNameList[i].type) {
              this.$message.error(
                "您选择的店铺类型与抓取的店铺类型不一致，请修改！"
              );
              return false;
            }

            // if (this.salesPlanForm.shopName.replace(/\s*/g,'') != this.originalShopNameList[i].name.replace(/\s*/g,'')) {
            //     this.$message.error('您选择的店铺与抓取的店铺不一致，请修改！')
            //     return
            // }
          }
        }
        for (var i in this.salesPlanForm.goodsItems) {
          if (this.salesPlanForm.goodsItems[i].entranceType == 1) {
            if (this.salesPlanForm.goodsItems[i].keyword == "") {
              this.$message.error("关键词不能为空！");
              return false;
            }
          }
          if (this.salesPlanForm.goodsItems[i].entranceType == 2) {
            if (this.salesPlanForm.goodsItems[i].keyword == "") {
              this.$message.error("淘口令不能为空！");
              return false;
            }
          }
          if (this.salesPlanForm.goodsItems[i].entranceType == 3) {
            if (this.salesPlanForm.goodsItems[i].keyword == "") {
              this.$message.error("二维码不能为空！");
              return false;
            }
          }
          if (this.creatPlanType == "sales") {
            if (this.salesPlanForm.goodsItems[i].payMoney == "") {
              this.$message.error("拍下价格不能为空！");
              return false;
            }
          }
        }
        if (this.salesPlanForm.allotType == 2) {
          if (this.totalAllotNum < this.intendOrderNum) {
            this.$message.error("还有未分配的单数！");
            return false;
          }
          // if (this.totalAllotNum > this.intendOrderNum) {
          //   this.$message.error('已分配总计超过计划中的单数！')
          //   return false
          // }
          if (this.creatPlanType === "sales") {
            if (this.totalAllotNum > this.intendOrderNum) {
              this.$message.error("已分配总计超过计划中的单数！");
              return false;
            }
          } else {
            if (this.totalAllotNum > this.trafficOrderNum) {
              this.$message.error("已分配总计超过计划中的单数！");
              return false;
            }
          }
        }
        if (this.isUploadGoodsImg) {
          if (this.salesPlanForm.goodsImg.indexOf("goods") < 0) {
            this.$message.error("商品主图未上传成功，请稍等或者重新上传");
            return false;
          }
        }
        if (!this.salesPlanForm.remark) {
          this.$message.error("请填写商家要求!");
          return false;
        }
        if (this.creatPlanType == "sales") {
          if (
            this.showCheckContentArr.indexOf(this.salesPlanForm.shopType) >= 0 &&
            this.checkContentStatus
          ) {
            if (
              this.salesPlanForm.checkContent.length >= 1 &&
              this.salesPlanForm.checkContent.length < 5
            ) {
              this.$message.error("商品详情页文本字数要为5个");
              return false;
            }
            if (this.salesPlanForm.checkContent.indexOf(" ") >= 0) {
              this.$message.error("商品详情页文本不能包含空格");
              return false;
            }
          }
        } else {
          var now = new Date();
          var startTimestamp = this.setPlanTime.startTime / 1000;
          var endTimestamp = this.setPlanTime.endTime / 1000;
          var startTimeOfHours = this.getDateOfHours(startTimestamp);
          var endTimeOfHours = this.getDateOfHours(endTimestamp);
          var startTimeOfDay = this.getDateOfDay(startTimestamp);
          var endTimeOfDay = this.getDateOfDay(endTimestamp);
          var dayNum = endTimeOfDay - startTimeOfDay;
          if (this.salesPlanForm.allotType == 1) {
            if (dayNum == 0) {
              if (startTimeOfHours < 6 || endTimeOfHours < 6) {
                this.$message.error("浏览单任务时间不能在00:00:00~06:00:00之间!");
                this.setPlanTime.startTime = now.getTime();
                this.setPlanTime.endTime =
                  new Date(new Date().toLocaleDateString()).getTime() +
                  24 * 60 * 60 * 1000 -
                  1;

                return false;
              }
            } else {
              this.$message.error("浏览单任务时间不能在00:00:00~06:00:00之间!");
              this.setPlanTime.startTime = now.getTime();
              this.setPlanTime.endTime =
                new Date(new Date().toLocaleDateString()).getTime() +
                24 * 60 * 60 * 1000 -
                1;

              return false;
            }
          }
        }
        return true;
      },
      // 其他费用（参数配置）
      otherExpenses(curServiceFeeList) {
        // 其他服务费
        this.payPlanInfo.otherService = {
          sex: {},
          age: {},
          model: {},
          credit: {},
          zqd: {}
        };
        let sexPriceText = "";
        let agePriceText = "";
        let creditPriceText = "";
        let modelPriceText = "";
        let zqdPriceText = "";
        let tkPriceText = "";

        let sexPriceNum = 0;
        let agePriceNum = 0;
        let creditPriceNum = 0;
        let modelPriceNum = 0;
        let zqdPriceNum = 0;
        let tkPriceNum = 0;

        var sexIsShow = false;
        var ageIsSHow = false;
        var creditIsShow = false;
        var modelIsSHow = false;
        var zqdIsShow = false;
        var tkIsSHow = false;

        zqdIsShow = this.salesPlanForm.zqd == "2" ? false : true;
        tkIsSHow = this.salesPlanForm.tk == "2" ? false : true;

        if (this.planType == "pay") {// 支付计划
          sexIsShow = this.salesPlanForm.sexId == "99" ? false : true;
          ageIsSHow = this.ageIdArr.indexOf("99") >= 0 ? false : true;
          creditIsShow =
            this.salesPlanForm.creditId == "99" ? false : true;
          modelIsSHow = this.salesPlanForm.modelId == "99" ? false : true;
        } else {// 新建 或 复制计划
          if (this.tagsList.sex_list.status == 1) {
            sexIsShow = this.salesPlanForm.sexId == "99" ? false : true;
          } else {
            sexIsShow = false;
            this.salesPlanForm.sexId == "99";
          }
          if (this.tagsList.age_list.status == 1) {
            ageIsSHow =
              this.ageIdArr.indexOf("99") >= 0 ? false : true;
          } else {
            ageIsSHow = false;
            this.salesPlanForm.ageId = "99";
          }
          if (this.tagsList.model_list.status == 1) {
            modelIsSHow =
              this.salesPlanForm.modelId == "99" ? false : true;
          } else {
            modelIsSHow = false;
            this.salesPlanForm.modelId = "99";
          }
          if (this.tagsList.credit_list.status == 1) {
            creditIsShow =
              this.salesPlanForm.creditId == "99" ? false : true;
          } else {
            creditIsShow = false;
            this.salesPlanForm.creditId = "99";
          }
        }

        curServiceFeeList.forEach((cell, cellIndex) => {
          if (cell.pay_type == 2) {
            if (cell.title.indexOf("性别") >= 0) {
              if (this.creatPlanType == "sales") {
                sexPriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `
                sexPriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
              }

              this.payPlanInfo.otherService.sex = {
                isShow: sexIsShow,
                name: "推手性别",
                price: sexPriceText,
                money: parseFloat(sexPriceNum).toFixed(2)
              };
            }
            if (cell.title.indexOf("年龄") >= 0) {
              if (this.creatPlanType == "sales") {
                agePriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `;
                agePriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
              }

              this.payPlanInfo.otherService.age = {
                isShow: ageIsSHow,
                name: "推手年龄",
                price: agePriceText,
                money: parseFloat(agePriceNum).toFixed(2)
              };
            }
            if (cell.title.indexOf("手机机型") >= 0) {
              if (this.creatPlanType == "sales") {
                modelPriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `;
                modelPriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
              }

              this.payPlanInfo.otherService.model = {
                isShow: modelIsSHow,
                name: "推手机型",
                price: modelPriceText,
                money: parseFloat(modelPriceNum).toFixed(2)
              };
            }
            if (cell.title.indexOf("信用") >= 0) {
              if (this.creatPlanType == "sales") {
                creditPriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `;
                creditPriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
              }

              this.payPlanInfo.otherService.credit = {
                isShow: creditIsShow,
                name: "推手信用",
                price: creditPriceText,
                money: parseFloat(creditPriceNum).toFixed(2)
              };
            }
            if (cell.title.indexOf("预约增权") >= 0) {
              if (this.creatPlanType == "sales") {
                zqdPriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `;
                zqdPriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
              }

              this.payPlanInfo.otherService.zqd = {
                isShow: zqdIsShow,
                name: "增权单",
                price: zqdPriceText,
                money: parseFloat(zqdPriceNum).toFixed(2)
              };
            }
            if (this.creatPlanType == "sales") {
              if (cell.title.indexOf("淘客检查") >= 0) {
                tkPriceText += `(${this.salesPlanForm.taskNum}*${cell.default_price}) + `;
                tkPriceNum +=
                  parseInt(this.salesPlanForm.taskNum) *
                  parseFloat(cell.default_price);
                let tk = {
                  isShow: tkIsSHow,
                  name: "淘客",
                  price: tkPriceText,
                  money: parseFloat(tkPriceNum).toFixed(2)
                };
                this.$set(this.payPlanInfo.otherService, "tk", tk);
              }
            }
          }
        });
      },
      creatPlan() {
        if (this.salesPlanForm.shopId) {
          this.shopNameList.map(item => {
            if (item.id == this.salesPlanForm.shopId) {
              let arrshopname = item.name.split("-");
              if (this.salesPlanForm.shopName.trim() != arrshopname[1].trim()) {
                this.$message.error("店铺名称与商品店铺名称不一致");
                return false;
              } else {
                // 副宝贝店铺名称是否一致
                if (this.salesPlanForm.goodsItems.length != 0) {
                  let goodsItemShopNameFlag = true
                  this.salesPlanForm.goodsItems.forEach(item => {
                    if (item.shopNameSon != arrshopname[1].trim()) {
                      this.$message.error("副宝贝只支持同店链接");
                      goodsItemShopNameFlag = false
                    }
                  })
                  if (!goodsItemShopNameFlag) return false
                }
                // 店铺名与选着的商品的店铺名称一致
                if (this.creatPlanType == "flow") {
                  var shopTypeArr = [1, 2];
                  if (shopTypeArr.indexOf(this.salesPlanForm.shopType) < 0) {
                    this.$message.error("浏览单只能发布天猫或者淘宝的商品！");
                    return;
                  }
                }
                this.$refs["goodsMainForm"].validate(valid => {
                  if (valid) {
                    let goodsItemsFlag = false
                    if (this.salesPlanForm.goodsItems.length != 0) {
                      for (let i in this.$refs["goodsForm"]) {
                        this.$refs["goodsForm"][i].validate(validSon => {
                          if (!validSon) {
                            this.$message.error("请完善副宝贝信息")
                            goodsItemsFlag = true
                            return
                          }
                        })
                      }

                    }
                    if (goodsItemsFlag) return;
                    if (!this.formValidate()) return;
                    console.log(this.salesPlanForm)
                    // return;
                    let discount = this.serviceFeeList["discount"];
                    let serviceFeeType = {
                      1: "service_fee_tb",
                      2: "service_fee_tm",
                      3: "service_fee_jd",
                      4: "service_fee_albb",
                      13: "service_fee_wph",
                      15: "service_fee_pdd",
                      20: "service_fee_onedragmore"
                    };
                    let serviceFee = serviceFeeType[this.salesPlanForm.shopType];
                    let curServiceFeeList = this.serviceFeeList[serviceFee];

                    this.payPlanInfo.capital = "";
                    this.payPlanInfo.commission = "";
                    this.payPlanInfo.commissionShow = "";
                    this.payPlanInfo.freezeMoney = 0;

                    // 主宝贝本金
                    this.payPlanInfo.capital = "(" +
                      parseFloat(this.salesPlanForm.payMoney).toFixed(2) +
                      "*" +
                      this.salesPlanForm.buyNum +
                      "*" +
                      this.salesPlanForm.taskNum +
                      ")" + "+"
                    this.payPlanInfo.freezeMoney = parseFloat(this.salesPlanForm.payMoney) *
                      parseInt(this.salesPlanForm.buyNum) *
                      parseInt(this.salesPlanForm.taskNum);
                    this.salesPlanForm.goodsItems.forEach((item, index) => {
                      if (this.creatPlanType == "sales") {
                        //本金
                        this.payPlanInfo.capital +=
                          (index > 0 ? "+" : "") +
                          ("(" +
                            parseFloat(item.payMoneySon).toFixed(2) +
                            "*" +
                            item.buyNumSon +
                            "*" +
                            this.salesPlanForm.taskNum +
                            ")");
                        if (this.salesPlanForm.rebateType != 1) {
                          this.payPlanInfo.freezeMoney +=
                            parseFloat(item.payMoneySon) *
                            parseInt(item.buyNumSon) *
                            parseInt(this.salesPlanForm.taskNum);
                        }
                        this.payPlanInfo.freezeMoney = parseFloat(
                          this.payPlanInfo.freezeMoney
                        );
                      }/* else {
                        for (var i in item.taskType) {
                          if (this.isBlank(flowTaskTypeList[i])) {
                            flowTaskTypeList[i] = 0;
                          }
                          flowTaskTypeList[i] += parseInt(item.taskType[i]);
                        }
                      }*/
                    });

                    //指定时间
                    let startTimeFormat = this.formatDate(
                      new Date(this.setPlanTime.startTime)
                    );
                    let endTimeFormat = this.setPlanTime.endTime
                      ? this.formatDate(new Date(this.setPlanTime.endTime))
                      : "";
                    let timeTypeName =
                      "(" + this.tabsList[this.salesPlanForm.allotType - 1].name + ")";
                    this.payPlanInfo.planTime = endTimeFormat
                      ? startTimeFormat + "--" + endTimeFormat
                      : startTimeFormat;
                    this.payPlanInfo.planTime =
                      this.payPlanInfo.planTime + timeTypeName;

                    // 本金 -- 通过初始的本金冻结金额获得
                    let capitalNum = this.payPlanInfo.freezeMoney;
                    // 佣金对应的对象
                    let commission = curServiceFeeList.filter((item) => {
                        if (
                          capitalNum / this.salesPlanForm.taskNum >= item.min &&
                          capitalNum / this.salesPlanForm.taskNum < item.max &&
                          this.salesPlanForm.shopType == item.platform_type
                        ) {
                          return item;
                        }
                      }
                    );
                    // 纯佣金 -- 未加数量
                    commission = commission[0].default_price;

                    // 佣金显示 * 数量
                    this.payPlanInfo.commission +=
                      "(" + this.salesPlanForm.taskNum + "*" + commission + ")";

                    // 副宝贝显示
                    this.payPlanInfo.commissionShow +=
                      "(" +
                      (this.salesPlanForm.taskNum) +
                      "*" +
                      (this.salesPlanForm.goodsItems.length) +
                      "*" +
                      this.payPlanInfo.copyCommission +
                      ")";
                    // this.payPlanInfo.commissionShow = this.salesPlanForm.taskNum + '*' + this.payPlanInfo.commissionShow;

                    // 冻结总额=本金加上佣金和副宝贝
                    this.payPlanInfo.freezeMoney +=
                      (this.salesPlanForm.taskNum * commission)
                      + (this.salesPlanForm.taskNum * this.salesPlanForm.goodsItems.length * this.payPlanInfo.copyCommission);

                    // 其他费用（参数配置）
                    this.otherExpenses(curServiceFeeList)

                    //处理其他服务，是否展示，去掉多余的+
                    Object.values(this.payPlanInfo.otherService).forEach(
                      (item, index) => {
                        if (item.isShow) {
                          this.isShowOtherService = true;
                          this.payPlanInfo.freezeMoney += parseFloat(item.money);
                        }
                        if (this.creatPlanType == "sales") {
                          let textLastIndex = item.price.lastIndexOf("+");
                          item.price = item.price.substring(0, textLastIndex - 1);
                        }
                      }
                    );

                    // 总金额后两位
                    this.payPlanInfo.freezeMoney =
                      this.payPlanInfo.freezeMoney.toFixed(2);
                    this.isShowPayPlanDialog = true;
                  } else {
                    this.$message.error("创建的计划信息不完善，请先填写");
                  }
                });
              }
            }
          });
          console.log(this.salesPlanForm)
        } else {
          this.$message.error("请选择店铺名称");
        }
      },
      payPlan() {
        if (this.payPlanInfo.freezeMoney == 0) {
          return this.$message.error("金额不能为0");
        }
        this.salesPlanForm.startTime = JSON.parse(
          JSON.stringify(Math.floor(this.setPlanTime.startTime / 1000))
        );
        this.salesPlanForm.endTime =
          this.salesPlanForm.allotType == 3
            ? ""
            : JSON.parse(
            JSON.stringify(Math.floor(this.setPlanTime.endTime / 1000))
            );
        this.salesPlanForm.overTime =
          this.salesPlanForm.planOver == 2
            ? ""
            : JSON.parse(
            JSON.stringify(Math.floor(this.setPlanTime.overTime / 1000))
            );
        if (this.salesPlanForm.placementArea) {
          this.salesPlanForm.placementArea = "+" + this.salesPlanForm.placementArea;
        }
        if (this.planType == "pay") {
          this.salesPlanForm.payType = "creating";
          this.salesPlanForm.id = this.planId;
        } else {
          this.salesPlanForm.payType = "";
        }
        this.submitLoading = true;
        if (this.creatPlanType == "sales") {
          apiCreateSaleDragPlan(this.salesPlanForm)
            .then(res => {
              if (res.code == 1 || res.code == 1001) {
                this.submitLoading = false;
                this.isShowPayPlanDialog = false;
                let _this = this
                return this.$alert(res.msg, '提示', {
                  confirmButtonText: '确定',
                  callback: action => {
                    _this.$router.push("./salesPlanList");
                  }
                })
              } else {
                this.submitLoading = false;
                this.$message.error(res.msg);
              }
            })
            .catch(res => {
              this.submitLoading = false;
              this.isShowPayPlanDialog = false;
              this.$message.error(res.msg);
            });
        } else {
          apiCreateFlowPlan(this.salesPlanForm)
            .then(res => {
              if (res.code == 1 || res.code == 1001) {
                this.submitLoading = false;
                this.isShowPayPlanDialog = false;
                let _this = this
                return this.$alert(res.msg, '提示', {
                  confirmButtonText: '确定',
                  callback: action => {
                    _this.$router.push("./flowPlanList");
                  }
                })
              } else {
                this.submitLoading = false;
                this.$message.error(res.msg);
              }
            })
            .catch(res => {
              this.submitLoading = false;
              this.isShowPayPlanDialog = false;
              this.$message.error(res.msg);
            });
        }
      },
      // 获取计划详情
      getPlanDetail() {
        if (this.planType == "pay") {
          this.isForbidModify = true;
          this.isForbidRevise = true;
          this.isForbidEditNum = true;
        } else {
          this.isForbidRevise = true;
        }

        var areaType = 1;
        if (this.creatPlanType == "sales") {
          this.$isClick(true);
          apiCopyPlan({
            token: this.userToken,
            id: this.planId
          })
            .then(res => {
              this.$isClick(false);
              if (res.code == 1) {
                this.analyzePlanData(res, areaType);
              } else {
                this.$message.error(res.msg);
              }
            })
            .catch(res => {
              this.$isClick(false);
              this.$message.error(res.msg);
            });
        } else {
          this.$isClick(true);
          apiFlowDetail({
            token: this.userToken,
            id: this.planId
          })
            .then(res => {
              this.$isClick(false);
              if (res.code == 1) {
                this.analyzePlanData(res, areaType);
              } else {
                this.$message.error(res.msg);
              }
            })
            .catch(res => {
              this.$isClick(false);
              this.$message.error(res.msg);
            });
        }
      },
      analyzePlanData(res, areaType) {
        if (res.msg.placementArea == "[]" || res.msg.placementArea == "") {
          this.salesPlanForm.placementArea = "";
        } else {
          var ite = unescape(res.msg.placementArea.replace(/\u/g, "%u"));
          ite = ite.replace(/\\/g, "");
          ite = ite.replace(/\"/g, "");

          if (ite.indexOf("-") >= 0) {
            ite = ite.replace(/\-/g, "");
            areaType = 2;
          } else {
            ite = ite.replace(/\+/g, "");
            areaType = 1;
          }
          var provinceArr = ite.split(",");
          for (var z in this.provinceOpitons) {
            this.provinceOpitons[z].checkedCities = [];
            this.provinceOpitons[z].isIndeterminate = false;
            this.provinceOpitons[z].checkAll = false;
          }
          for (var province in this.provinceOpitons) {
            for (var i in provinceArr) {
              for (var j in this.provinceOpitons[province].province) {
                if (
                  provinceArr[i] == this.provinceOpitons[province].province[j]
                ) {
                  this.provinceOpitons[province].checkedCities.push(
                    provinceArr[i]
                  );
                  if (
                    this.provinceOpitons[province].checkedCities.length ==
                    this.provinceOpitons[province].province.length
                  ) {
                    this.provinceOpitons[province].isIndeterminate = false;
                  } else {
                    this.provinceOpitons[province].isIndeterminate = true;
                  }
                  this.provinceOpitons[province].checkAll = true;
                }
              }
            }
            if (this.provinceOpitons[province].checkedCities.length > 0) {
              this.salesPlanForm.placementArea +=
                this.provinceOpitons[province].checkedCities.join(",") + ",";
            }
          }
          if (areaType == 2) {
            this.salesPlanForm.placementArea = "";
            for (var x in this.provinceOpitons) {
              var newArr = [];
              var checkedCitiesArr = this.provinceOpitons[x].checkedCities;
              if (checkedCitiesArr.length == 0) {
                this.provinceOpitons[x].checkedCities = this.provinceOpitons[
                  x
                  ].province;
              } else {
                for (var j in this.provinceOpitons[x].province) {
                  if (
                    checkedCitiesArr.indexOf(
                      this.provinceOpitons[x].province[j]
                    ) < 0
                  ) {
                    newArr.push(this.provinceOpitons[x].province[j]);
                  }
                }
                this.provinceOpitons[x].checkedCities = newArr;
              }
              if (
                this.provinceOpitons[x].checkedCities.length ==
                this.provinceOpitons[x].province.length
              ) {
                this.provinceOpitons[x].isIndeterminate = false;
              } else {
                this.provinceOpitons[x].isIndeterminate = true;
              }
              if (this.provinceOpitons[x].checkedCities.length == 0) {
                this.provinceOpitons[x].checkAll = false;
                this.provinceOpitons[x].isIndeterminate = false;
              } else {
                this.provinceOpitons[x].checkAll = true;
              }
              if (this.provinceOpitons[x].checkedCities.length > 0) {
                this.salesPlanForm.placementArea +=
                  this.provinceOpitons[x].checkedCities.join(",") + ",";
              }
            }
          }
        }
        // this.isForbidModify = false
        this.salesPlanForm.placementArea = this.salesPlanForm.placementArea.substring(
          0,
          this.salesPlanForm.placementArea.length - 1
        );
        this.salesPlanForm.planName = res.msg.planName; //计划名称
        this.salesPlanForm.shopId = res.msg.shopId; //店铺名称
        this.salesPlanForm.goodsUrl = res.msg.goodsUrl; //商品url
        this.salesPlanForm.productId = res.msg.productId;// 商品id
        this.salesPlanForm.shopType = res.msg.shopType; //店铺种类
        this.salesPlanForm.goodsTitle = res.msg.goodsTitle; //商品标题
        this.salesPlanForm.shopName = res.msg.shopName; //店铺名称
        this.salesPlanForm.entranceType = res.msg.entranceType; //店铺名称
        this.salesPlanForm.keyword = res.msg.keyword; //二维码|关键词
        this.salesPlanForm.taskNum = res.msg.taskNum; //销量任务
        this.salesPlanForm.buyNum = res.msg.buyNum; //每单拍
        this.salesPlanForm.payMoney = res.msg.payMoney; //拍下单价
        this.salesPlanForm.sku = res.msg.sku; //拍下规格
        this.salesPlanForm.showMoney = res.msg.showMoney; //搜索展示价格
        this.salesPlanForm.payPerson = res.msg.payPerson; //付款人数
        this.salesPlanForm.goodsAddress = res.msg.goodsAddress;// 商品归属地
        this.salesPlanForm.goodsSeller = res.msg.goodsSeller; //掌柜名称
        this.salesPlanForm.goodsMainImg = res.msg.goodsMainImg; //商品主图

        this.salesPlanForm.tk = res.msg.tk || 2; //淘客
        this.salesPlanForm.remark = res.msg.remark;
        this.salesPlanForm.sexId =
          res.msg.sexId == 99 ? res.msg.sexId.toString() : res.msg.sexId;
        this.ageIdArr = [];
        if (res.msg.ageId == 99) {
          this.ageIdArr.push("99");
        } else {
          var idArr = res.msg.ageId.toString().split(",");
          for (var idItem in idArr) {
            this.ageIdArr.push(parseInt(idArr[idItem]));
          }
        }
        this.salesPlanForm.creditId =
          res.msg.creditId == 99
            ? res.msg.creditId.toString()
            : res.msg.creditId;
        this.salesPlanForm.zqd = res.msg.zqd;
        this.salesPlanForm.zqdType = !res.msg.zqdType
          ? "0"
          : res.msg.zqdType.toString();
        this.salesPlanForm.modelId =
          res.msg.modelId == 99 ? res.msg.modelId.toString() : res.msg.modelId;
        this.salesPlanForm.allotType = parseInt(res.msg.allotType);
        this.salesPlanForm.checkContent = res.msg.checkContent
          ? res.msg.checkContent
          : "";
        this.platFormTypeChange();
        if (res.msg.overTime !== "") {
          if (res.msg.overTime == 0) {
            this.salesPlanForm.planOver = 2;
            this.setPlanTime.overTime = "";
          } else {
            this.salesPlanForm.planOver = 1;
            this.setPlanTime.overTime = "";
          }
        }
        var planfor = ""
        if (res.msg.planTime) {
          planfor = JSON.parse(res.msg.planTime);
        }

        if (this.planType == "pay") {
          this.$set(this.salesPlanForm, "startTime", parseInt(res.msg.startTime));
          this.$set(this.salesPlanForm, "endTime", parseInt(res.msg.endTime));
          this.$set(
            this.setPlanTime,
            "startTime",
            parseInt(res.msg.startTime) * 1000
          );
          this.$set(
            this.setPlanTime,
            "endTime",
            parseInt(res.msg.endTime) * 1000
          );
        }
        if (this.salesPlanForm.allotType == 2) {
          if (this.planType == "pay") {
            this.$forceUpdate(); //强制刷新
            this.salesPlanForm.planTime = planfor;
            this.totalAllocation();
          } else {
            this.changeTimeTab(this.salesPlanForm.allotType);
          }
        }
        if (this.creatPlanType == "sales") {
          // 关键字
          res.msg.goodsItems.forEach((item, index) => {
            let goodsItem = {
              goodsUrlSon: item.goodsUrlSon, // 商品链接
              productIdSon: item.productIdSon, // 商品id
              goodsTitleSon: item.goodsTitleSon, // 商品标题
              buyNumSon: item.buyNumSon, // 每单拍n件
              payMoneySon: item.payMoneySon, // 拍下单价
              skuSon: item.skuSon, // 拍下规格
              showMoneySon: item.showMoneySon, // 搜索展示价格
              goodsAddressSon: item.goodsAddressSon,// 商品归属地
              goodsImg: item.goodsImg, // 商品主图
              shopNameSon: item.shopNameSon,// 店铺名称

              /*shopNameSon: res.shopNameSon, // 店铺名称
              shopIdSon: res.shopIdSon, // 店铺id
              goodsSellerSon: item.goodsSellerSon || "", // 掌柜昵称
              payPersonSon: res.msg.payPersonSon, // 付款人数约
              */
            };
            this.salesPlanForm.goodsItems.push(goodsItem)
          });
        } else {
          res.msg.flowNum.forEach((item, index) => {
            this.salesPlanForm.goodsItems[index] = {
              keyword: item.keyword,
              entranceType: item.entrance_type,
              taskType: {
                1: 0,
                2: 0,
                3: 0,
                4: 0,
                5: 0,
                6: 0,
                7: 0,
                8: 0
              }
            };
            Object.keys(item.flow_task_info).forEach((ite, inde) => {
              this.salesPlanForm.goodsItems[index].taskType[inde + 1] =
                item.flow_task_info[ite].num;
            });
          });
        }
      },
      isBlank(val) {
        if (val == null || val == "") {
          return true;
        }
      },
      //=========================销量=========================
      getCurSelectQrcode(index) {
        this.curQrcodeIndex = index;
      },
      qrcodeSuccess(res, file) {
        this.salesPlanForm.keyword = res.msg;
        this.$forceUpdate();
        this.$message.success("上传成功");
      },
      qrcodeBeforeAvatarUpload(file) {
        const isLt2M = file.size / 1024 / 1024 < 10;
        if (!isLt2M) {
          this.$message.error("上传头像图片大小不能超过 10MB!");
        }
        return isLt2M;
      },
      getCheckContentText() {
        this.salesPlanForm.checkContent = this.salesPlanForm.checkContent.replace(
          /[^\a-\z\A-\Z0-9\u4E00-\u9FA5\！\!\:\;\：\；\，\,\.\。\【】\{}\ \()\-\（）]/g,
          ""
        );
        if (
          this.salesPlanForm.checkContent.length >= 1 &&
          this.salesPlanForm.checkContent.length < 5
        ) {
          this.checkContent = "";
          this.$message.error("商品详情页文本字数要为5个");
          return;
        }
        if (this.salesPlanForm.checkContent.indexOf(" ") >= 0) {
          this.checkContent = "";
          this.$message.error("商品详情页文本不能包含空格");
          return;
        }
        if (this.salesPlanForm.checkContent.length == 5) {
          var leftStr = this.salesPlanForm.checkContent.substring(0, 2);
          var rightStr = this.salesPlanForm.checkContent.substring(3, 5);
          this.checkContent = leftStr + "( )" + rightStr;
        }
      }
      //=========================流量===========================
    }
  };
</script>

<style lang="less">
  #create-plan {
    .plan-card {
      background: #ffffff;
      margin-bottom: 16px;
      box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
      padding-bottom: 16px;
      border-radius: 5px;
      border-top: 3px solid @themeColor;

      .plan-card-header {
        background: #ecf5ff;
        padding: 10px;
        display: flex;
        align-items: center;
        margin-bottom: 16px;

        .title {
          line-height: 20px;
          border-left: 3px solid #666666;
          padding-left: 10px;
          font-size: 16px;
          font-weight: 700;
          color: #333333;
          width: 150px;
        }

        .tips {
          font-size: 14px;
          color: red;
        }
      }

      .plan-card-content {
        padding: 10px 20px;

        .zqd-tips {
          color: red;
          font-size: 14px;
          margin-bottom: 10px;
        }

        &.other-style {
          display: flex;
          justify-content: space-between;
          align-items: center;
        }

        .goods-form {
          .el-form-item {
            margin-bottom: 17px;
          }

          .form-input {
            width: 300px;
          }

          .form-btn {
            display: inline-block;
            margin-left: 20px;
            border: 1px solid @themeColor;
            border-radius: 4px;
            font-size: 12px;
            color: @themeColor;
            text-align: center;
            padding: 8px 20px;
          }

          .form-btn-tips {
            display: inline-block;
            margin-left: 20px;
            border: 1px solid #909090;
            border-radius: 4px;
            font-size: 12px;
            color: #909090;
            text-align: center;
            line-height: 28px;
            padding: 0 20px;
          }

          .other-info {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .other-info-input {
              width: 100px;
            }
          }
        }

        .goods-img-box {
          margin-right: 50px;

          .goods-img {
            text-align: center;
            color: #606266;

            img {
              width: 260px;
              height: 260px;
              border: 1px dashed #666666;
            }

            .upload-icon {
              width: 260px;
              height: 260px;
              border: 1px dashed #666666;
              text-align: center;
              line-height: 260px;
              color: #a5a5a5;
              font-size: 30px;
            }
          }
        }

        // 任务信息样式
        .task-card {
          display: flex;
          align-items: center;
          justify-content: space-between;
          border: 1px dashed #a5a5a5;
          padding: 36px 20px 20px 20px;

          .task-card-left {
            .form-box {
              margin-bottom: 16px;

              .title {
                font-size: 14px;
                color: @fontSubtitleColor;
                width: 80px;
                text-align: right;
                display: inline-block;

                .star-text {
                  color: red;
                }
              }

              .form-input {
                width: 200px;
                vertical-align: middle;
                margin-left: 5px;
              }

              img {
                width: 200px;
                height: 200px;
                border: 1px dashed #a5a5a5;
                vertical-align: text-top;
              }

              .qrcode-img-box {
                display: inline-block;
                margin-left: 5px;

                img {
                  width: 200px;
                  height: 200px;
                  border: 1px dashed #a5a5a5;
                }

                .upload-icon {
                  width: 200px;
                  height: 200px;
                  border: 1px dashed #a5a5a5;
                  text-align: center;
                  line-height: 200px;
                  color: #a5a5a5;
                  font-size: 20px;
                }
              }
            }
          }

          .task-card-center {
            &.flow-center {
              display: flex;
              align-items: center;
            }

            .center-cell {
              display: flex;
              align-items: center;
            }

            .form-box {
              margin-bottom: 16px;
              margin-right: 20px;
              color: @fontSubtitleColor;
              font-size: 14px;

              .title {
                font-size: 14px;
                color: @fontSubtitleColor;
                width: 80px;
                text-align: right;
                display: inline-block;

                .star-text {
                  color: red;
                }
              }

              .form-input {
                width: 150px;
                vertical-align: middle;
                margin: 0 5px;
              }
            }

            .center-row {
              .flow-form-box {
                margin-bottom: 16px;
                margin-right: 20px;
                color: @fontSubtitleColor;
                font-size: 14px;

                .title {
                  font-size: 14px;
                  color: @fontSubtitleColor;
                  width: 160px;
                  text-align: right;
                  display: inline-block;
                }

                .form-input {
                  width: 100px;
                  vertical-align: middle;
                  margin: 0 5px;
                }
              }
            }
          }

          .task-card-right {
            i {
              font-size: 20px;
              padding: 8px;
              cursor: pointer;
              display: block;
            }

            .add-task-icon {
              color: @themeColor;
            }

            .cut-task-icon {
              color: red;
            }
          }
        }

        .time-type-box {
          display: flex;
          align-items: center;

          .title {
            font-size: 14px;
            color: @fontSubtitleColor;
            width: 80px;
            text-align: right;
            display: inline-block;
          }

          .tabs-nav {
            border-radius: 5px;
            border: 1px solid #e0e0e0;

            &.disabled-click {
              background: #f5f7fa;

              .tab {
                cursor: not-allowed;

                &.active {
                  background: #dce5f3;
                  color: #333333;
                }
              }
            }

            .tab {
              display: inline-block;
              font-size: 13px;
              color: @fontSubtitleColor;
              padding: 5px 12px;
              cursor: pointer;

              &:nth-child(1) {
                &.active {
                  border-top-left-radius: 5px;
                  border-bottom-left-radius: 5px;
                }
              }

              &:nth-child(2) {
                border-left: 1px solid #a5a5a5;
                border-right: 1px solid #a5a5a5;
              }

              &:nth-child(3) {
                &.active {
                  border-top-right-radius: 5px;
                  border-bottom-right-radius: 5px;
                }
              }

              &.active {
                color: #ffffff;
                background: @themeColor;
              }
            }
          }
        }

        .set-time-box {
          display: flex;
          align-items: center;
          margin: 30px 0;

          .title {
            font-size: 14px;
            color: @fontSubtitleColor;
            width: 80px;
            text-align: right;
            display: inline-block;
          }

          .time-select-box {
            .check-box {
              margin-left: 30px;

              .el-checkbox__label {
                color: @fontSubtitleColor;
                font-weight: normal;
                margin-right: 10px;
              }
            }
          }
        }

        .set-number {
          position: relative;
          // display: flex;
          .title {
            font-size: 14px;
            color: @fontSubtitleColor;
            width: 80px;
            text-align: right;
            display: inline-block;
          }

          .plan-time-box {
            background: #f5f5f5;
            border-radius: 5px;
            display: inline-block;
            margin-right: 10px;
            margin-bottom: 10px;
            text-align: center;
            font-size: 14px;
            padding: 10px;
            border-radius: 5px;

            .time {
              margin-bottom: 10px;
            }
          }

          .el-tag {
            //background: @themeColor;
            //color: #fff;
            margin: 10px 0;
          }

          .count-number {
            font-size: 16px;
            color: #333333;
            text-align: right;
            margin-right: 50px;
          }

          .el-collapse {
            border: none;
            padding-bottom: 10px;

            .is-active {
              .el-tag {
                background: @themeColor;
                color: #fff;
                margin: 10px 0;
              }
            }
          }

          .set-n-row {
            padding: 0 10px 10px 10px;
          }

          //.el-collapse{
          //  border: none;
          //}
        }

        .remark-box {
          margin-top: 20px;
          border-top: 1px dashed #e0e0e0;
          padding: 25px 0;

          .remark-example-box {
            .remark-example {
              color: @themeColor;
              border: 1px solid @themeColor;
              padding: 5px 15px;
              border-radius: 5px;
              font-size: 12px;
              cursor: pointer;
              display: inline-block;
              margin-right: 10px;
              margin-bottom: 10px;
            }
          }

          .textarea-box {
            font-size: 14px;
            color: @fontSubtitleColor;
            margin-top: 32px;

            .title {
              color: red;
            }

            .el-textarea {
              vertical-align: text-top;
            }
          }
        }

        .select-area-btn {
          width: 60%;
          text-align: left;
          overflow: hidden;
        }

        .price-text {
          display: inline-block;
          color: red;
          margin-left: 16px;
          font-size: 14px;
        }

        .tips {
          font-size: 14px;
          color: red;
        }

        .title {
          font-size: 14px;
          color: @fontSubtitleColor;
        }

        .check-content-box {
          font-size: 14px;
          color: @fontSubtitleColor;
          margin-top: 16px;

          .input {
            width: 200px;
            margin: 0 16px;
          }
        }

        .radio-box {
          margin-left: 16px;
        }

        .el-radio {
          color: @fontSubtitleColor;
          font-weight: normal;
        }

        .zpd-type-data {
          margin-top: 32px;
        }
      }
    }

    .page-footer {
      text-align: center;

      .show-pay-info-btn {
        background: @themeColor;
        color: #ffffff;
        font-size: 14px;
        height: 40px;
        width: 120px;
        line-height: 40px;
        padding: 0;
        margin-top: 16px;
      }
    }

    .select-goods-modal {
      /deep/ .el-dialog {
        .el-dialog__body {
          padding: 0 20px !important;
        }
      }

      .select-goods-modal-header {
        .el-form .el-form-item {
          padding-left: 0;
          padding-right: 15px;
          display: inline-flex;

          /deep/ .el-form-item__content {
            width: 150px !important;
          }

          .inquire-btn {
            height: 32px !important;
            padding: 0px 10px !important;
            background: @themeColor;
            color: #ffffff;

            i {
              font-size: 14px;
            }
          }
        }
      }

      .select-goods-modal-content {
        max-height: 300px;
        overflow-y: scroll;

        .goods-img-box {
          width: 180px;
          display: inline-block;
          margin: 8px;
          cursor: pointer;
          border: 1px solid transparent;
          box-shadow: 0px 0px 3px #666;
          padding: 5px;
          border-radius: 3px;

          .text {
            font-size: 14px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .goods-img {
            width: 180px;
            height: 180px;
          }
        }

        .selectStyle {
          border: 1px solid red;
        }
      }
    }

    .area-dialog {
      .tips {
        color: red;
        margin: 0 10px 10px 0;
        font-size: 14px;
      }

      .area-content {
        border: 1px solid #e0e0e0;
        margin: 20px 10px 0 10px;

        /deep/ .el-checkbox__label {
          color: rgb(96, 98, 102) !important;
          font-weight: initial !important;
        }

        .province-select {
          padding: 10px 20px;
          border-bottom: 1px solid #e0e0e0;
        }
      }

      .left-box {
        display: inline-block;
        border-right: 1px solid #7d7d7d;
        margin-right: 15px;
        padding-right: 15px;
      }

      .save-btn {
        text-align: center;

        .el-button {
          border: 0px solid;
          padding: 0;
          height: 35px;
          line-height: 35px;
          width: 100px;
          background: @themeColor;
          color: #ffffff;
        }
      }
    }

    .pay-plan-dialog {
      .dialog-content {
        .card {
          display: flex;
          align-items: center;
          border: 1px solid #e0e0e0;
          border-radius: 3px;
          margin-bottom: 10px;

          .title {
            padding: 10px 16px;
            border: 1px solid #ecf5ff;
            width: 165px;
            text-align: left;
            background: #ecf5ff;
          }

          .content {
            padding: 11px 16px;
            border-left: 1px solid #e0e0e0;
            background: #ffffff;
            flex: 1;
          }
        }
      }
    }

    .no-data-img {
      text-align: center;
      margin-top: 80px;

      .tips {
        font-size: 14px;
        margin-top: 10px;
      }
    }
  }
</style>
